Removing Spaces from Filenames on Windows

I received 60 documents to put online, beautifully named, but with SPACES!!! Aaaah!

Thankfully, you can bulk remove them in a powershell: hooray! This simple, understandable and beautiful solution on Stack Overflow shows you how:

  • Open the command prompt, by searching for CMD
  • Open a powershell by typing in powershell
  • cd to the folder the files are in
  • and try this command
    get-childitem *.pdf | foreach {rename-item $_ $_.name.replace(" ","")}
    replace pdf with whatever the relevant extension is

That’s it, works beautifully!

6 thoughts on “Removing Spaces from Filenames on Windows”

  1. Thank you!! This has saved me hours and hours of typing, renaming and deleting every single space off the hundreds of Atari 2600 binary files that I downloaded to play on my Flashback I got for Christmas šŸ˜€

    Thanks again! Happy Christmas!

    Reply
  2. Beautiful, such time saver.
    Following command replaces space with underscore
    get-childitem *.png | foreach {rename-item $_ $_.name.replace(” “,”_”)}

    Reply
    • Hi Carol, what I’m doing with this line:
      get-childitem *.pdf | foreach {rename-item $_ $_.name.replace(" ","")}
      is replace the space with nothing. There is nothing between the second quotation marks. It basically says replace " " [space] with "" [nothing].
      So it is removing the spaces. That’s all it does. I hope that helps!

      Reply

Leave a Comment