Unable to Delete Folder – Invalid Path

Our scanning application output files to an invalid directory. The path settings were set to [LastName], [FirstName] [IDNumber]. The problem was the data did not have any values in the IDNumber field. So, the directory was created as “Smith, John “ (note the space at the end).

If you try to create a folder in Windows and put a space at the end, when you hit Enter or click outside the box it will automatically trim that space for you. Well, the way that our scanning application outputs it somehow allowed the directory to get created with the trailing space.

The problem is, that is an invalid path, so if you double-click in the directory and then try to open any of the files they will error. Windows also will not let you cut, copy, rename or delete the folders because again it thinks you are asking for something ‘invalid’.

The only way we could remove them was by using the cmd prompt (as administrator) and running the following command:

rd "\\?\C:\Output\InvalidFolderName "

Note the use of UNC path, \\? is a cmd prompt shortcut for this local computer. The above command successfully deleted the folders, we fixed the naming convention in our scanning software and were able to re-output to the correct directories.

Leave a thought