Thursday, October 9, 2014

windows - How to delete directories with path/names too long for normal delete


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

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?


Answer



I believe I've found a way to delete things from cmd. Originally I tried the del command, but that didn't work. Then I remembered rmdir. Doing the following:


rmdir /S /Q 

seems to have worked.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...