File name starting with space

Interesting question on the forum regarding finding files with a file name starting with a space.

First problem was creating some files to match the criteria. Renaming in file explorer didn’t work so back to PowerShell

PS> Rename-Item -Path C:\test\file1.txt -NewName "C:\test\ file1.txt"

PS> Rename-Item -Path C:\test\junk.txt -NewName "C:\test\ junk.txt"

Make sure you put the new name in quotes so the space is included as part of the file name

After that its actually quite easy

PS> Get-ChildItem -Path C:\test\ -Filter ' *.txt'

     Directory: C:\test

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       30/06/2017     15:38             16  file1.txt
-a----       30/06/2017     10:50             26  junk.txt

Use the Filter parameter and specify ‘ *.txt’ as the pattern you want to match

This entry was posted in Powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s