How to delete a file with a path too long to be deleted in 3 easy steps

How to delete a file with a path too long to be deleted in 3 easy steps:

Did you ever try to delete a folder and got that annoying message that one or more files could not be deleted because their path was too long?
This tutorial will show you how to delete these files in 3 easy steps:

Step 1: make an empty folder

Just make an empty folder, for example in the parent folder of the folder that needs to be deleted.
We will remove this empty folder again in the last step.

mkdir empty_dir

Step 2: move all files to the newly created empty folder

We will use “robocopy” to move all files to the root of the new folder. This will remove the long paths of the original folder.

robocopy empty_dir the_dir_to_delete /s /mir

Step 3: cleanup

As a last step we can now simple remove the folder to be deleted and the temporary created folder:

rmdir empty_dir
rmdir the_dir_to_delete


This method works because robocopy internally uses the Unicode-aware versions of Win32 functions, with the \\?\ prefix for file paths.
These functions have a limit of 2¹⁶-1 (32,767) characters instead of 259.


This tutorial showed in 3 easy steps how to delete a folder containing files with a too long path to be deleted.

If you liked this tutorial, then please link to it and/or like it with the button below.

%d bloggers like this: