387
134
Windows seems to have a length limit on file names when trying to delete, though it won't prevent those files from being created.
Our build process creates a number of temporary files (many build off of a WSDL) that run afoul of this limit. Our ant script is somehow able to delete them when doing a clean, but sometimes I need to delete the workarea directory (where all the temp files go) without actually doing a full clean from ant.
This is the same errors this question, but the answers there don't really work for me as I'm dealing with a directory, not a file, and I don't always know what specific files or subdirectories are causing the problem. And I'm trying to avoid any manual process (other than triggering a single command) to actually delete them.
If I try deleting the directory from Explorer I get the error
Cannot delete [file name]: The file name you specified is not valid or too long.
Specify a different file name
Trying Remove-Item
in powershell gives the following error:
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 than 248 characters.
At line:1 char:12
+ Remove-Item <<<< -force -Recurse <directory>
Does anyone know of any tools or easy ways to get around this delete error without having to manually find the problem files and move/rename them?
By Far the simplest solution: https://www.youtube.com/watch?v=qQTyTprFAOg
– TaW – 2015-11-28T21:54:10.027using
Ubuntu
or any otherLinux Bootable CD
we can boot our computer toUbuntu
or any other OS for temporary.then we can select the folder and we can delete it easily. – Kelum Priyadarshane – 2015-11-29T04:04:33.2231
This older question has some interesting answers too: http://superuser.com/questions/45697/how-to-delete-a-file-in-windows-with-a-too-long-filename/392431#392431
– AdamV – 2015-12-03T11:01:55.363Ya, the simplest solution will be install 7-zip and compress it and don't forget to check the box 'Delete after compression' and then delete the zip file also. Thanks @Dentrasi. – Avishek – 2016-11-29T17:32:31.757
Actually, is there anybody who knows why Windows made such a restriction after all? It seems to make little sense since a lot of third-party tools can just circumvent this restriction with ease, so it certainly doesn't seem to be something inherent with the filesystem or whatnot. Seems to only add difficulty for the user, what for? – xji – 2017-01-12T19:10:57.730
If you happen to have IntelliJ installed, deleting the file/folder from there will work. I haven't tried any other code editors. (PS, I cannot add this as an answer due to the Protected status.) – Tormod Haugene – 2017-01-30T10:04:39.793
it is 2017, and it seems M$ don't want developer use their OS, If you are NodeJS developer, NPM may create a lot of nested folder. And you can not delete at all. – vanduc1102 – 2017-03-29T12:44:58.277
https://superuser.com/a/1263183/439537 – Andrew – 2017-10-28T00:37:42.270
2I found the solution just before posting this question, but since others may run into this I decided to post it so that they could find the solution I ran across. – Herms – 2009-12-03T19:24:39.027
Oh I know, but generally when I do things like this I leave the question "unanswered" for a while to see if anyone else has a better solution. – Herms – 2009-12-03T20:42:27.137