Recently I ran into an issue where a directory name had a trailing
space like “Temp “. I tried all the normal ways of deleting the file
— explorer, del, rd , rd /s /q, etc. Of course, none of these worked
because the Win32 name space strips out trailing spaces and trailing
periods before performing any functions on the file. So if there was
a file named “ImportantStuff.txt” and another called
“ImportantStuff.txt “, the first file without the trailing space would
be opened. To delete the file, I used the syntax ‘rd /s /q
“\?c:temp” ‘ to delete the directory from the command prompt. Any
other command like ren, move, del would also work in the same syntax.

For example:
del “\?c:temp.txt ”
ren “\?c:temp.txt ” c:temp.txt

Advertisements