How to Delete Long Path Files in Windows?
How to delete long path files in Windows if the system refuses to delete the selected files? This post will show force deleting long file names and how to deeply clean large files.
Scenario: The file name you specified is not valid or too long.
“When I try to delete the directory using Explorer, I receive the following error: —Cannot delete [file name]: The file name you specified is not valid or too long; and when I used Powershell, I received the following error: Remove -Item: The supplied path, file name, or both are insufficiently lengthy. The fully qualified file name and the directory name must be smaller than 260 and 248 characters, respectively. Line 1 char 12 + - Remove-Item - force –Recurse
Is it possible to safely remove lengthy path files in Windows and thoroughly delete large files in Windows?
File name is too long to delete
When attempting to remove some files, because Windows accepts file names with up to 255 characters, including the directory path, a directory or file, if the selected files or folder exceeds the limit, it cannot be operated.
This problem causes a lot of hassle when users wish to remove a directory or a deeply stored file. Thus, in this post, we list 2 workable solutions to help you force delete long name files.
How to delete long path files in Windows?
To resolve the problem that is caused by the system, the best way is to use the system built-in tool. In this part, we’ll show you how to delete long path files in Windows with Command Prompt orders. There are 2 ways to solve the problem, the commands might be a little complex, please be careful.
Way 1. Use DIR commands to force delete long name file
Step 1. e Explorer and navigate to the directory where the target files are located. Press and hold Shift, then right-click on an empty area. Choose “Open command window here”.
Step 2. Type: DIR /X, if the directory contains more files than can be displayed on a single screen, use the command DIR /X /P instead so that it will pause at every screen length so you can examine the file list.
DIR /X command will list all the directories and files in the current directory, and it will also list all the files and directories. In the example, you can see how the dummy txt file with a nonsensical (and hundreds of characters long) filename is reduced to a simple “WHYSOL~1.TXT”.
So now we need to arm it with the short name of the file or directory you wish to delete, you can simply issue a DEL command for the file.
Step 3. Type: DEL WHYSOL~1.TXT
Then Windows will delete the file without complaint, and you can run DIR /X again to confirm or just check the directory in Windows Explorer.
Way 2. Delete long file names via robocopy commands
You can also use robocopy commands.
Step 1. Type CMD in the search box and right-click the best match, choose “Run as administrator”. Now, create an empty directory, you can type: mkdir C:\emptyfolder
Step 2. Type the following lines and press “Enter”.
Robocopy C:\emptyfolder C:\name of folder/purge
For example, if the name of the newly created folder is “C:\EmptyFolder” and the folder with a long path is “C:\FolderToBeCleaned\Copy\MyFiles\BackupFolder\Copy\MyFile…”, then the deleting command is “robocopy C:\Emptyfolder C:\FolderToBeCleaned /purge”.
Then the files in the target path will be removed.
Further reading: How to find large files in Windows and delete them?
Some users may think that deleting files is a simple task. However, if you meet the above situation, deleting files can also be an annoying problem. Just like the files with a long name, files with large sizes stored deeply in the system also cannot be removed easily. Users might not even know their existence. But they will find that no matter how many times they use a cleaning program to clear the system and disks, there always have some available space occupied by some unknown files.
If you have such a problem, it’s possible that there are some large files that have been recognized as important by your system like exe files. Since you can’t find them in File Explorer, the best choice is to use a third-party tool to scan them and you can remove them according to your needs.
Here, we recommend you AOMEI Partition Assistant Professional, a disk and partition manager for Windows 11/10/8/8.1/7/XP users. Its “Delete Large Files” function can filter all large files and list them for you to choose to remove.
Step 1. Install and launch AOMEI Partition Assistant, then click "Free up" and "Delete Large Files".
Step 2. In the pop-up window, select the partitions that you want to find large files, and click "Start Scan" to scan for large files.
Step 3. When the scan is complete, all large files found are listed. Tick the files you want to delete, and then click the "Delete" button. You can also delete files marked in red if you’re sure they won’t hurt any programs or your system.
Step 4. This step will list all the files you have ticked to delete, click "Delete Now" after confirming that it is correct, then these files will be deleted successfully.
Then the large files can disappear from your PC. Don't worry, if you have deleted the wrong files, there is an option to recover lost data immediately. If you want to release more space to your system drive, you can try “Allocate Free Space” or “App Mover” features according to the condition of your device.
Final words
In this post, we show you two methods for how to delete long-path files in Windows. If you have files with names too long, you can try the methods above. And if you wish to clear some deeply stored files, AOMEI Partition Assistant can help you.
Besides removing large files, you can also use this tool to clone disk, migrate OS to another disk, convert partition style to GPT/MBR without deleting partitions, and so on.
And if you’re using a Windows Server system 2022/2019/2016/2012(R2)/2008(R2)/2003, you can choose the Server Edition to manage your devices.