Deleting a directory with a trailing space in Windows 10/11

The problem

At some point, you may come upon a directory that was created with a trailing space in it that you want to rename or get rid of. Windows will try to prevent you from creating directories like this but they still can be created programatically or through API's and when they are, they're a pain to get rid of.

The explorer will tell you it doesn't exist, if you try to delete it from the command prompt it will give you a similiar error. For instance, if you typed rmdir "test " to delete a folder named test with a trailing space, it wouldn't find it.

The fix

This is a workaround that tricks the command prompt into parsing the folder. Note the trailing backslash. My working theory is that by putting the trailing backslash at the end that it treats it like an escape character leaving the space after test in place.

rmdir "test \"

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

Peter - Monday, May 16, 2022

Thank you very much. Your workaround worked perfectly. I can stop pulling out my hair now.