[trailingSpaceKilla] Free tool to remove trailing spaces from filenames and directories

In a mixed PC / Mac environment, you can encounter the situation where Mac systems create filename or folders with a trailing space at the end. While files with the names are no problems for a Mac to work with, Windows systems cannot move/delete/rename the folders – they just give access denied messages.

It is possible to delete these files with the following commands:

rd /s “\\?\D:\path\to\file ”
del “\\?\D:\path\to\file.txt ”

I’ve tried to find a way to prevent this situation from happening, but have been unsuccessful so far. The next best thing I can do is hunt the files down and correct them. After spending quite a while looking all over the place for a VBScript or powershell script that would allow me to find and remove the trailing spaces I was still unsuccessful, so had a crack at developing a C# command line application to do this instead…

Enter: trailingSpaceKilla…

Run it from the command line (Or as a scheduled task!), and point it towards a directory. It will find any files or folders with the bad space at the end, and replace it with an underscore (_), allowing full access from Windows systems once again! If you’re doing to use this, please run it on some test files first, as NO WARRANTY IS PROVIDED- USE AT YOUR OWN RISK. (That said, I’ve just run it on our production file servers, with no issues)

Download – trailingSpaceKilla.exe (12k)


  • Jay commented on January 31, 2013

    Thanks for the tool. It is a real life saver!

  • emaleroland commented on August 30, 2013

    It finds the folders and files and reports it changed them but it doesn’t.

  • Todd commented on November 4, 2013

    would you consider updating this to also fix file with trailing periods? I have a number of files and directories from my Mac users with both trailing spaces and trailing periods. Both are a real hassle to deal with.

  • George commented on November 22, 2013

    BRILLIANT!! :) I’d been tearing my hair out all day!!

    I’m now bald but I have now been able to delete the directory that had a space at the end of its name!!

    FYI… it was created when I extracted files from a backup image to a new directory which was created using DriveImage XML – my fault for not noticing I’d named the directory with a space at the end. :(

  • Seb commented on January 12, 2015

    hi! thanks for this tool. unfortunately on my platforms it is too only saying it had renamed the folders, but it didnt. can you provide the source, so that we could have a look? thank you!

  • John commented on May 17, 2015

    I found another simple solution: create a new folder next to it and copy the contents of the space-containing-folder into the new folder. Now you files are saved!
    It’s not yet possible to delete the old folder however. I heard that Ubuntu Live CD can help to fix these problems.

  • Test commented on April 15, 2016


  • FkinMacs commented on April 23, 2016

    Works great. Somehow the commands I found weren’t working? Maybe I had something wrong. Anyway, thanks. I recall having the same issue with trailing periods, don’t remember how I fixed back then. It’d be nice if this tool fixes those too. I’ll keep it close. I kinda hate Max systems. The trailing spaces, periods (I know it’s more of an issue with Windows, why does it allow them to be created in the first place?), the ds_store files that litter everything. A big pain.

  • Swong commented on June 16, 2016

    Hi, This fixed our issue as well. We have spent hours trying to resolve this. Thanks

  • Bill commented on June 26, 2017

    Easiest way for me….
    Install 7ZIP
    Use 7ZIP explorer and simply delete the folder trailing spaces.

  • Mark Harburn commented on September 15, 2017

    @Bill – no good if you have hundreds this was a lifesaver for me tried all kinds. I was about to spin up a linux vm it was that bad.

    Only thing i would say is I had to run it several times to complete the job on the same folder. However thats a tiny price to pay for the time it saved!

  • Nicky commented on August 23, 2018

    Dunno if you still read this post, but dude, you are AWESOME. Thank you!

  • Mat commented on August 31, 2018

    Fantastic tool. Are you able to work out / fix the fact you have to run it multiple times on the same folder to complete? I have over 5000 items to delete and it only seems to do a maximum of 2 folders at once

Leave a Reply

Your email address will not be published. Required fields are marked *