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…
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)