When cleaning files from a Windows Operating System (OS), you are halted with errors relating to the filename or the file path being too long. This is due to a 255/260 character limit on Windows Operating Systems preventing the files in a directory from being removed.
Follow this article to learn how to remove all files from a directory that have a longer than allowed filenames or paths by using the Microsoft utility "Robust File Copy" (Robocopy).
Windows 7+
Symptoms
- Source Path Too Long
- The source file name(s) are larger than is supported by the file system.
How to Solve the Issue
The actions performed in the below process will permanently remove all contents, such as files and folders, in your specified path.
Using Robocopy to delete files that have a path and filename that is too long:
- Notate the folder directory path that needs its contents to be deleted.
- Example: C:\FolderToBeCleaned
- From Windows File Explorer, create an empty folder anywhere on the hard drive:
- Example: C:\EmptyFolder
- Open a Windows Command Prompt as an Administrator.
- Type the following command, replacing the example paths with yours:
- Robocopy C:\EmptyFolder C:\FolderToBeCleaned /purge
- Press the Enter key.
The folder contents are now deleted: