Solve “Source Path Too Long”, Can’t Delete Folder in Windows


Having issues deleting a folder or a file? Are you getting messages about filename too long or path too long? Then read on for a simple solution.

Windows uses a naming convention called “Long Filenames (LFN)”. The LFN system supports file names up to 255 characters. Windows also has a flag called MAX_PATH which has value 260, meaning a file path can have a maximum of 260 characters including the drive. So, when files are created by other programs that have more than 260 characters they cannot be deleted using Windows or DOS commands. You’ll get the message file name too long or path too long.

Destination Path Too Long

Method 1: Using 7zip

7-Zip is open source file archiver with a high compression ratio.

  1. Find the path of the file with the filename that is too long to delete
  2. Navigate to the file, as if you’re going to create an archive within the 7-zip or winrar application, right click on the file (or F2) and choose to rename. Give the file a shorter name.
  3. Success! the file now has a shorter name and can be deleted.

Method 2: Using Robocopy

Robocopy is default available on Windows 7 and higher. Robocopy is a Windows command to copy files from one location to another.

The syntax for Robocopy is quite easy:
robocopy <Source> <Destination> [<File>[ …]] [<Options>]

There is an option called PURGE. The PURGE option deletes destination files and directories that no longer exist in the source. We will use this flag to delete the folders recursively.

  1. create an empty directory (C:\emptyfolder). Let’s say the folder we want to delete is C:\deletefolder
  2. Run robocopy c:\emptyfolder c:\deletefolder /purge. Since there are no files or folders in the source directory (C:\emptyfolder), it simply deletes the files and folders under the target directory (C:\deletefolder) recursively!

Source Path too Long

Method 3 (For NodeJS users): Using RimRaf

Working with Node.js on Windows platform, can be tricky and it might happen that some trivial action will fail, for instance removing nodemodules folder. This is due to recursive references of folders and files within nodemodules, which ultimately ends up with a long name (path).

  1. Install RimRaf npm install rimraf -g
  2. Delete the folder using rimraf nodemodules

5 thoughts on “Solve “Source Path Too Long”, Can’t Delete Folder in Windows

  1. I would like to suggest you, try LongPathTool to resolve this issue. This tool is very helpful to resolve the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *