PowerShell for Windows Admins

Jul 5 2017   1:39PM GMT

File name starting with space

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


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

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: