Fix: Cannot Delete File, The File Name You Specified Is Invalid Or Too Long
Files or folders can sometimes not be deleted because of file name restrictions in Windows. See, Windows supports file names of up to 255 characters, which includes the directory path. If a directory or file surpasses that limit it cannot be deleted. Many users at this moment assume a corrupt file on the hard drive that is preventing the deletion. While that is a possibility, it may be simpler than that.
The error message reads (variants possible):
cannot delete file: the file name you specified is invalid or too long. Specify a different file name.
The following trick may help in removing the file and the directory structure from the system. Please note that it is not necessary to count the characters used in the file path, if it looks extraordinarily long then it may use indeed more characters than the allowed maximum.
We have already established that deletion does not work. The best option? Renaming. It is still possible to rename directories or the file name, so that the total count drops below the character limit. This can be done both in Windows Explorer, or on the command line. Just select a folder, and rename it to a single character. Repeat the procedure until the file path length has dropped considerably.
Deleting the file and folder structure should then work both in Windows Explorer and the command line. There are other solutions on how to cope with this situation. Another possibility is to map a drive to a folder in the path, to shorten the url structure, or to find a software or operating system that can manipulate those files and folder structures.
Did you ever encounter files that could not be deleted because of their length? What have you done to fix the situation?
You may also ask yourself how those structures appear on your system. It can be that you have downloaded and extracted an archive that included a nested folder structure, or are using a data drive on Windows and another operating system that does not have these restrictions. Whatever the reason, your best bet of deleting, renaming or moving files or folders if you receive the "not valid or too long" error is to shorten its path by renaming folders.
Advertisement
I do not understand this solution, can you please thro some light on it. As in my case, I have an external drive “E” for pen drive and unable to delete some *.mp3 files. Can you help me out on this issue.
Same
SOLVED!
I COULD NOT RENAME NEITHER DELETE SOME FILES.
I JUST MOVED THE FOLDER THAT CONTAINED THE PROBLEMATIC FILES CLOSE TO THE ROOT LOCATION (e.g. C:/) AND THEN I WAS ABLE TO DELETE THEM!
by moving the folder closer to root the overall name characters count was reduced
THANKS MARTIN!
Unlocker works fantastic. just when installing it, antivirus will detect a virus and block the virus only, but the rest of program will continue to install. just wait for it.
Solution that worked for me:
Start from the root directory you are attempting to delete, rename every folder going down the tree to a single character, I did the alphabet. By the time I hit M, I was able to delete the contents.
Hope that helps.
With downloading “Long Path Tool” you will be able to fix your long path errors.
Try and download ” Long Path Tool ” is also useful in situations where you see these error messages: Cannot read from source file or disk, there has been a sharing violation, cannot delete file or folder, the file name you specified is not valid or too long, the source or destination file may be in use and many other file managing errors.
DO NOT USE THIS “Tool”!!!
I believe it caused my computer to have repeat BOOTS; Crashing My computer constantly until I was able to correct it (on my own) as my tried-and-true anti-malware software was Unable to detect and remove it!
I performed the http://www.VirusTotal scan on it. All the engines (except one, Trend Micro) gave it a clean bill of health. TM informed that LPT was actually a T-R-O-J-AN!
I will stick with my Teracopy from now on.
S_R_A
My case is so critical that even I can’t upload it to virustotal! They’re some unknown files that have filled my flash memory space but I can’t delete even rename them! And unlocker couldn’t do anything about them! I’m searching but any new idea is appreciated…
Have you tried using Long Path Tool? I have the same problem as yours and it had been resolved using that tool. Check it.
Sometimes simplifying the file or folder name doesn’t work.And if you have 3000+ files, im sure you can’t rename them all. So the best thing to do i guess is to use a third party app like longpathtool. It can solve issues like this and errors like 1320 in windows 7. i hope this can help.
Have you tried long path tool it is the best software it will help you
Why don’t you check out Long Path Tool? It would be very useful, it would help you solve your problems. Check it out.
Brilliant – what an easy solution: Renamed all folders to one letter and then could delete them. Thanks!
I was having this issues with my 2 gig SD card. I was unable to delete some (maybe corrupt) files because “the filename you specified is not valid or too long”. I couldn’t delete the files at all. I’m running windows 7. I fixed the issue by right clicking the SD file and then clicked “Format”. It erased everything on it. Of course, I was careful to make sure there was nothing on it that I cared about. Make sure you transfer all files that you want to save before doing this. They WILL be lost otherwise.
This is a Windows* OS/file system issue.The cause is directory paths on the drive is longer than 255 characters (including spaces).There’s a lot of additional softwares which can fix this problem like Long Path Tool.
http://PathTooDeep.com
Long Path Tool can simplify and probably end your problems in unlocking, managing and renaming files that appear to have a long filename. Since in some instances, you may have experienced problems accessing, managing and even renaming files that have more than 255 characters, this utility has been made to answer this particular scenario. If you have also encountered problems like error messages that tell you that the path too long, too long path, destination path too long or cannot delete file then this program is definitely for you. This will totally take place of Windows Explorer, Far Manager or other file managing utilities since this is maybe used in any type of Operating System even the earliest Windows 95 version.
Followed the advice in this article by shortening the folder names successively to reduce the length of the file name, and voila! I was able to delete the offending files in a jiffy! Thanks for the simple solution.
Use a software program called DelinvFile http://www.purgeie.com/delinv/index.htm
I am also faced the same problem but i got the solution from the lonpathtool.com.
i also have faced the same problme and following software sort out my problem
http://www.longPathTool.com
Little features of this softwares are:
Path too long.
Error cannot delete file: cannot read from source file or disk.
Cannot delete file: Access is denied.
There has been a sharing violation.
Cannot delete file or folder The file name you specified is not valid or too long.
Specify a different file name.
The source or destination file may be in use.
The file is in use by another program or user.
Error Deleting File or Folder
Make sure the disk is not full or write-protected and that the file is not currently in use.
Path too deep.
Just in case anyone is interested:
long path tool moved to http://www.pathtoolong.com
Do you have error messages?, like :
Cannot delete file: Access is denied
There has been a sharing violation.
The source or destination file may be in use.
The file is in use by another program or user.
Make sure the disk is not full or write-protected and that the file is not currently in use.
If yes, our progam will be helpful for you.
Windows Explorer/FAR would fail to copy/delete/rename any pathname longer than 256 characters. Our program LONG PATH Tool can handle pathnames of any length, up to the internal Windows limit of 32,000 characters.
Fast speed of long path folder/files search.
No special system requirements. LONG PATH Tool works on any Windows version (NT/2000/XP/Vista/Windows 7).
Delete system locked files
Can delete files even from mapped network folders
Can list files and paths which have file path more than 200 characters long.
Close application that uses the file
Unload locking process
Copy and delete files and folders
Delete after reboot
Omits file name you specified is not valid or too long
This command was a useful solution for me:
SUBST
Create a virtual drive from directory where the problem is, then try to delete/rename the stuck file/folder.
Hope this help.
Regards!
Another terrific tool is FastCopy.
http://ipmsg.org/tools/fastcopy.html.en
Internally it bypass the 255 Windows chars limitations when copying/deleting.
had this problem with a file downlaoded from net, too long a name and also Zero bytes, xp gave me no choice but to reinstall if i wanted rid of the dam file, xp didnt recognise it as a file because it was seemed to not even be a file, but there it was! and nothing i tried , renaming, going into dos to rename/delete !
I like the solution at this site :)
http://www.rarst.net/script/delete-path-too-long/
Heh, I should have probably linked to this in my comment above. :)
back in the time (the age of Windows 98 and ME) i used to go directlyto DOS booting and head to the directory of the file, since DOS will not show that very name (instead; it will shorten it with a hyphen in the end) you can so easily delete it.
in case of Windows XP, the only way i remeber using was to go safe mode and delete the cursed file.
I have this problem on a regular basis as Mac users on our server create directory structures 10 levels deep and then find they can’t rename or move a file. Windows has no problem creating the long paths but can’t delete them. The only thing that has work has been to create shares at some point in the path, delete the files, create a new share, etc. until the path is cleaned up.
Of course, they will go and the same thing again the next day…
Unlocker works sometimes, but when it doesn’t, first I try to delete via a command line, if that doesn’t work then I use a live CD to boot into linux and delete the file(s) there.
I haven’t had exactly this problem but one similar to, which was having a zero-bite file unable to remove because the system just couldn’t read it, for the system there was no such file ! That was a few years ago and I had finally found an application which read and removed the file … I have an old version but the website and application are still going strong:
JRT Wine Software, LLC – Delete FXP Files
http://www.deletefxpfiles.com/index2.html
If it can help as it had helped me, great !
I have had some success using the DOS command SUBST to cut a long path down to a drive letter.
Did not have problems with too long ones, but with under windows in filesnames not allowed chars like the ” : “. It was impossible to rename the file. So just started Ubuntu Live CD and renamed the file. It might also work for too long filepaths?
I usually map a drive partway into the path and then dig into the mapped drive to delete the file.
One of the options in unlocker is to rename the file / folder.
Works fine for me every time I come access this mess. So I too vote for unlocker.
Of course Microsoft should just fix the bug in the first place!!
Problem is in charset. Any program dont see this named file, some yes but cannot delete or run. Solution is rename it to normal system charset and then delete. Bigger problem is folder, if you use rename or copy, it makes copy to file, not a folder. scandisk or checkdisk cant correct this….. solution is to use a filemanager with correct charset (ascii)
From my experience Unlocker doesn’t help with overly long paths. I get such regularly at work with one of programs. There might be differences of Windows versions and other specifics of course, in my case it fails.
I use batch script that recursively destroys folder tree with robocopy.
I am a fan of unlocker and have been using it for years. It’s one of my goto tools along with Sysinternals Process Explorer and other utils. BUT there are times when doing all of the above and using every other ‘delete/unlock’ tool will not work. What I have found is that the long filename and ‘directory not empty’ thing can be fixed by using a bulk file rename tool 1st renaming the file(s) and or directories incrementally like 001 etc., then deleting (sometimes still with unlocker). There are loads of freeware bulk file/dir renamers around so I won’t list them use Google. I see this alot with incomplete backup file restores.
Martin, Mehdi S is right i often encounter this problem and unlocker is always doing, the trick for me. Great program.
Great, did not know that.
Unlocker dose work. I use it in the field for this exact problem.
Hmmm . . . should be able to go to Task Manager, end process –explorer.exe, delete file, and restart explorer.exe. Maybe MoveOnBoot. Hard to say–heard about the problem; never had to personally deal with it.
I understand an embedded feature of windows is the virtual impossibility or removing ‘too long’ file names. Often they are created when visiting websites and therefore may contain information a user want’s to delete.
One way to circumvent such issues is to use sandboxie (http://www.sandboxie.com) by ensuring that the software/browser that creates such ‘too long’ file names is captured within a sandboxie container. The container can also be placed on a ram disk, so everything just vanishes at shutdown.
The container could also be placed on a separate disk or usb stick, which can be overwritten/erased/formatted when needed.
The only way to give accurate advice is to be advised which program created the file name or cut and paste a copy of it here, indicating which folders it is contained in.
unlocker ftw…
NOTHING worked. No Command tricks, no PowerShell tricks, NOTHING. It hit me. It wasn’t JUST the filename, but the entire pathname. It would not let me rename the file, but going back to the root directory, and drilling into about 4 layers thick, then renaming the next folder in the path to 1, then the next one to 1 and the next and the next. Finally I was able to delete 1\1\1\1\1\1\1\obsolete_file.txt I was then able to delete any rouge folders and then rename the remaining folders back. (Hint–if you can’t remember the folder names, write them down first. Office staff typically does not like it when you ask “what was that folder’s name supposed to be again?”)
THANK YOU Trick with multiple “1” worked for me! Very nice!
I do not think that Unlocker can help in this case.
The solution is simple.
Example: c:/folder/folder/folder/nameoffilethatistolong.txt
Change each folder name to f so c:/f/f/f/changthename.txt
txs, it works
Maybe I’m wrong, but i’d swear I used unlocker for that bug before…As for your trick, I used to do that too :)