Windows Explorer and many Windows applications including PowerShell are limited to 255 characters max file path. Whilst this limitation is in place at an application level, the NTFS file system does not support this limit. In fact file paths can be created remotely over the SMB protocol to exceed this limit which is how most file servers get stuck with folder paths administrators can no longer maintain using the native Windows Explorer application.
When attempting to delete folders using Windows Explorer the following errors may be experienced:
The source file name(s) are larger than is supported by the file system. Try moving to a location which has a shorter path name, or renaming to shorter name(s) before attempting this operation.
I am going to show you a way to remove excessively long file paths without using third party tools such as Long Path Tool which come at a price or booting into different operating systems such as Linux to remove the unwanted file paths.
One Microsoft application which is not limited to the 255 character limit is robocopy.exe. I know this as I often move large volumes of data with Robocopy between server infrastructure and have never been hit with a file path limitation. As a result, this is the tool I chose to remove the data.
If you use robocopy with the /MIR switch, it will make the destination folder exactly the same as the source folder. So if the source folder is empty, it will delete all data in the destination empty and in result deleting the content.
I have a path here with 3 users which have folder structures which exceed 255 characters. Windows Explorer failed to remove these folders.
I created an empty folder on C:\ called test then used the mirror switch to copy the test folder to the HomeDrives folder.
robocopy /MIR c:\test E:\UserData\HomeDrives
After running the command all my user folders under E:\UserData\HomeDrives were deleted.
This is a handy trick for dealing with folders on file servers which have excessive amounts of long folder structures which exceed the 255 character limit.
Hope this has been helpful, feel free to leave me a comment below.
When attempting to delete folders using Windows Explorer the following errors may be experienced:
The source file name(s) are larger than is supported by the file system. Try moving to a location which has a shorter path name, or renaming to shorter name(s) before attempting this operation.
An unexpected error is keeping you from deleting the folder. If you continue to receive this error, you can use the error code to search for help with this problem.
Error: 0x80004005: Unspecified error
Even new applications from Microsoft such as PowerShell do not support file paths longer then 255 characters despite this being supported by NTFS.
Remove-Item: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less then 248 characters.
I am going to show you a way to remove excessively long file paths without using third party tools such as Long Path Tool which come at a price or booting into different operating systems such as Linux to remove the unwanted file paths.
One Microsoft application which is not limited to the 255 character limit is robocopy.exe. I know this as I often move large volumes of data with Robocopy between server infrastructure and have never been hit with a file path limitation. As a result, this is the tool I chose to remove the data.
If you use robocopy with the /MIR switch, it will make the destination folder exactly the same as the source folder. So if the source folder is empty, it will delete all data in the destination empty and in result deleting the content.
I have a path here with 3 users which have folder structures which exceed 255 characters. Windows Explorer failed to remove these folders.
I created an empty folder on C:\ called test then used the mirror switch to copy the test folder to the HomeDrives folder.
robocopy /MIR c:\test E:\UserData\HomeDrives
After running the command all my user folders under E:\UserData\HomeDrives were deleted.
This is a handy trick for dealing with folders on file servers which have excessive amounts of long folder structures which exceed the 255 character limit.
Hope this has been helpful, feel free to leave me a comment below.
Thank you sooooo much, robocopy FTW!
ReplyDeleteG8, I use Robocopy to move data and then delete... Thank You...!
ReplyDeleteThanks alot Clint It was very helpful...
ReplyDeleteGreat Tips ! Thank you !!
ReplyDeleteMan that was a great tip! Saved the day from this annoying problem!
ReplyDeleteThanks heaps. Just in case, you didn't specify the switch needed to delete stuff - I didn't want to mirror files, I just wanted to delete the long (endlessly long) files that had somehow built up as a product of using a synch program. Using /PURGE seemed to be the key and the following certainly worked for me in deleting all the long files and folder names in the affected directory. A lifesaver, thanks again:
ReplyDeletec:\users\peter>robocopy /PURGE c:\test d:\minidrivesynch\a
Naturally the command could be run from anywhere I just happened to be at the users\peter prompt. Interestingly even though I didn't want to copy the files (i.e. so you would have thought /PURGE of the target directory would work) the command did not work unless the copy path was there as well (i.e. c:\test). That's weird, but it worked. I'm free!!!!
PERFECT. Thank you. The "PURGE" worked as you wrote.
DeleteAt the beginning I had 21 folders interleaved (identical names) + 2 subfolders: origins unknown! It seemed to continue growing on.
Impossible to delete: file paths too long. Roland Geissler, now nightmare-free! Thanks.
cannot say thank you enough, i've been around pc since model ibm 86, never knew the robocopy command existed, it is a joy
ReplyDeletewhat i did notice, perhaps my ignorance, the command is finicky if the directories have more than one word it seems it counts the spaces as well, at least what i think
tried quite a few combinations and only one whereas both the going and coming had "one" word, anything with a space and the command failed me.
what i did was send the irritating files to a not important usb drive and reformatted the drive after. it's safer, don't need to touch any of the directories.
and the command doesn't care what kind of drive it is. so the further away from the computer the cleaner. MY OPINION
Thank you.. It worked like wonder .. Thanks again..
ReplyDeletein my case robocopy /purge has crash after a while, perhaps because there're 2000+ sub directory which I've no idea where it came from. after some googling I found suggestion to use 7-zip file manager. just browse to that dir with 7-zip and simply hit shift del, and its gone.
ReplyDeleteThank you so much, Its all the nodejs node modules which only is creating the longest source file name paths in windows NTFS file system. Thanks to 7zip for helping.
DeleteAnonymous; please don't be unamed!! Just kidding!! Thanks a ton!! Just please add one more thing; use "Shift + Del" as simple "Del" will call the OS delete routine where as "Shift+Del" 7zip's own routine which clear up explicitly and forcefully and what ever you may say but worked like charm!! Thanks a looooooooooooooooooooooooooootf of again!!.
DeleteAs with others: I've been playing around with Node and NPM and created some long files paths.Perhaps just deciding to delete the file directory wasn't the best idea but once done I was left with this issue. Robocopy /MIR blankdir nodedir helped resolve it. Thanks.
ReplyDeleteSimply cool, works great!
ReplyDeleteThanks!
Works well... Thanks
ReplyDeleteAwesome worked like a charm
ReplyDeleteGreat Tip !!!!!!
ReplyDeleteThank much
ReplyDeleteThanks alot! Great tip.
ReplyDeleteNow that was easy, Thanks!!
ReplyDeleteeasy way u can try long path tool :). this is the best way i think :)
ReplyDeleteThanks bloke from WA ! This worked on my Win2008 server on a folder where the files were not even visible except to Unlocker and the DOS command rmdir /S neither of which could actually do anything about it. I suspect that these files were put there using Robocopy by my sysadmin in the first place, so the solution is kinda neat. And with Robocopy already installed it took about 5 seconds to accomplish .....
ReplyDeleteThis issue had driven me insane since I had heaps and heaps of such folders(with pathnames longer than 255) due to my mistake with one of the sync scripts written using robocopy. I had tried many options including using long path tool which actually caused BSOD on my pc and scared me to death. I was hence unwilling to use any third party software for this job. And then, I came across your solution and it WORKED WONDERS. The MIR command with robocopy ran for like 12 minutes(imagine the junk I had which needed to be get ridden of!) and voila, I could finally delete the folders. I can't thank you enough. Cheers :)
ReplyDeleteThis works perfectly!
ReplyDeleteGreat info! Download "Long Path Tool" since I downloaded it I never encountered the same error ever.
ReplyDeleteExcillent Work!!
ReplyDeleteThanks :)
Thanks!
ReplyDeleteMy idea is that the best solution is Long Path Tool.
ReplyDeleteBIGGGGG THAAAAAANKS!
ReplyDeleteNice!
ReplyDeleteThanks bro.... !!
ReplyDeleteThank you so so much! this tip saved me from a lot of headache ;)
ReplyDeleteThank you very much for this tip.
ReplyDeleteThis is awesome! Thanks!
ReplyDeleteThanks a lot for this well illustrated post!
ReplyDeleteIt saves me a lot of time and patience.
Fred, Montpellier, France
Thank you! Clear description and instruction. Worked first time. Problem solved!
ReplyDeleteAwesome! Really save my life... T_T
ReplyDeleteThat is worked for me as well, Thanks for the post :)
ReplyDeleteThis is the only thing that I found that solved this issue. Thanks!!
ReplyDeletehello friends,please try long path tool , its really helpful
ReplyDeleteWonderful - Thanks
ReplyDeleteThanks!
ReplyDeleteThe only solution I could find.
This not deletes just hide files you morons check
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks! This was the best solution for me to use in a PowerShell deployment-script. The script failed because of genereated class-files, so I added the robocode line before the rmdir command:
ReplyDeleterobocopy /MIR D:\install\empty $existingDomanDir | Out-Null
execBat "rmdir /S /Q $existingDomanDir"
Note the piping of the output of robocopy. This is done because robocopy is pretty verbose
Thanks!
ReplyDeleteAwesome.......... thanks a lot for the solution
ReplyDeleteThank you. It was a great help.
ReplyDeleteThank you, you just saved me a ton of time!
ReplyDeleteGreat..! Thank you. It's working.... :)
ReplyDelete
ReplyDeleteIf you trying to resolve path too long problem
Use long path tool.... It's very easy solution and you can find it..... By writing at Google search "long path tool"
great writeup, thanks! Very easy fix.
ReplyDeleteTry Long Path Tool program
ReplyDeleteThis is a great help for those of us who were never pleased with MS for this in the first place. Thanks for showing me a way out of a 2.6 TB tangled mess! AJ
ReplyDeletehow to use such files
ReplyDeleteGreat trick, worked perfectly!
ReplyDeleteGreat post! Thank you!
ReplyDeleteLong Path Tool could be the answer to your problem.
ReplyDeleteAmazing! it's working on me, thank you so much!!!
ReplyDeleteIt worked, but... it did not copy the files in the offending folder to the one that I created for this purpose, it simply deleted them, which I wanted to do anyway - fortunately.
ReplyDeletethanks a lot, it worked to me too.... thanks one more time.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks a lot :)
ReplyDeleteThank you Very much! solved a problem which was bugging me over the weekend!!!
ReplyDeleteThanks... worked like a charm :)
ReplyDeleteYou rocks man, thanks!
ReplyDeleteYou can use “Long Path Tool” !
ReplyDeletethank you, saved me a lot of time!
ReplyDeletePerfect thanks :)
ReplyDeleteThanks, It's really great tip...
ReplyDeleteAwesome tip, this worked perfectly for me on Windows 10
ReplyDeleteThank you very much!
ReplyDeleteThanks a lot!! It worked like a magic :)
ReplyDeleteSuper awesome !! Great help man
ReplyDeleteGreat tip! Thanks
ReplyDeleteI used to have similar problems too, but after using "long path tool" everything was solved. Try this software and you would be glad you did.
ReplyDeleteBeautiful Tip and Share! Thank You much for the help. I ran into the exceeding min characters for using git and nodeJs. Installing packages sometimes can exceed the limit. I am not sure why, but possibly for the fact of custom builds using angulars command line interface.
ReplyDeleteLong Path Tool help me a lot when i have an issue like file deleting or renaming the file. Also good to use if file name and file extension is too long
ReplyDeleteWhen I try to delete or move the file, It gives me the error 0x80004005. I also cannot get to the Command prompt san someone help me?
ReplyDeleteEmail me with a possible solution ASAP: shmadamading@gmail.com
Thank you so much! Worked for me. (:
ReplyDeleteCool Man
ReplyDeleteawesome trick worked
ReplyDeleteSaweet trick!
ReplyDeleteWorked perfect on Server2012r2 with folders that contained invalid characters and missing all security descriptors.
Check disk failed but Robocopy got it done without a restart.
Thank You!
I have used Long Path Tool, It works as per needs.
ReplyDeleteI have used Long Path Tool, It works as per needs.
ReplyDeleteLong path error!
ReplyDelete"Long path tool" is very helpful for this problem. You can solve this problem like copy, delete, long path files by using this tool.
I used to have similar problems too, but after using "long path tool" everything was solved.
Thank you very much.
ReplyDeleteSolution very good.
The Internet thanks you. This is the kind of stuff that makes earth amazing.
ReplyDeleteThanks mate, worked like a charm
ReplyDeleteDude, you saved my life...it's incredible how some people seem to fit entire novels into their folder names...even more unbelievable is the fact that even Windows 10 still can't handle filenames longer than 255 characters...welcome to 1985.
ReplyDelete
ReplyDelete“Long Path Tool” is very helpful for this error !
best solution for your problem.
ReplyDelete“Long Path Tool” is very helpful for this error !
best solution for your problem.
ReplyDeleteLong path tool is the very good program for error, unlock solution.
Try it and solve your problem.
I used long path tool and I solve my error, unlock problem solution.