Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a very long path in a directory

Tags:

windows

ant

I have a pretty weird problem with a folder structure that was created by my ant build...it created a folder structure such that C:helper/class/helper/class/helper/class and goes on for a very long time.

I was wondering if there was some script that I could use to delete these folders using cmd on Windows 7.

I have already tried:

rmdir /s /q

along with trying to use :

robocopy "C:helper/class/helper/class/helper/class" C:Test

But still I got no luck...

Does anyone have any suggestions or script that I could use for a bat file to recursively delete this structure?

like image 381
koala421 Avatar asked Dec 11 '13 15:12

koala421


People also ask

Can't delete because its pathname is too long?

Solving "Too Long" Filename Errors The trick is to auto-generate a shorter filename and use that. Open a command prompt in the directory where the file is located. Use a DOS command to get the short filename in the 8.3 filename format. Now, use the DEL command in DOS for the file to delete the file.


5 Answers

Try

 robocopy /e /b /purge c:\empty c:\folder-to-delete
like image 147
Harry Johnston Avatar answered Oct 05 '22 21:10

Harry Johnston


del and rmdir commands can't delete folders with long names. But 7-Zip can! Right click on a folder which should be deleted. Select "Add to Archive" in 7-Zip context menu and set "Delete files after compression" option in "Add to Archive" 7-Zip dialog. 7-Zip create archive files and delete folder with long paths! After that you can delete archive file.

enter image description here

like image 31
Володин Андрей Avatar answered Oct 05 '22 22:10

Володин Андрей


The problem may be due to a limit on how long paths may be in Windows itself. There's a limit of around 1551 characters. It's very easy in a Java project (or even a C# .NET project) to create these very long paths. Especially if you're putting your project under something like C:\Documents and Settings\Baron Van Hushoven\Documents\Projects\My Project -- 74 characters long).

If this is your issue, you may be forced to use to the Subst command. This allows you to create a drive letter that represent another path, then you can use that drive letter to help create a shorter path.

C:\> subst x: "C:\Documents and Settings\Baron Van Hushoven\Documents\Projects\My Project"

Now, you can use X: as the root of your project which will shorten the paths you're attempting to delete by 74 characters which may just be enough for Windows to be able to access these files.


1. The limit is actually 260, but once you put in C:\, you're pretty much down to 255. Ironically, NTFS can handle extremely long paths of around 32K, and Windows can also handle these long names too. You might be able to prefix the path with "\\?\" as in\?\C:\Documents ...` However, I don't believe that works in Windows Explorer or the Command Line Console.

like image 38
David W. Avatar answered Oct 05 '22 22:10

David W.


I have had much more success with the built-in del command in Windows 7.

I have seen del /s /q work in situations where rmdir /s /q does not.

like image 30
Tim Hoppen Avatar answered Oct 05 '22 21:10

Tim Hoppen


i've done it with "FastCopy ver3.13"

source : path of to long directory

dest: c:\x\

operation mode (drop down): Delete all (delete all files / dirs by force)

executed it 3 times, and my problem was solved. robocopy, 7zip does not work for me.

like image 26
twoplustwoisfive Avatar answered Oct 05 '22 22:10

twoplustwoisfive