Batch to delete directory with path-too-long problem.
Moderator: DosItHelp
-
- Posts: 18
- Joined: 02 May 2013 06:09
Batch to delete directory with path-too-long problem.
I've had an interesting problem yesterday. I somehow managed to create infinite loop that created directories so deep that Windows could not handle any more. To clarify, the result was i:\one\two\one\two\one\two ... \one\two ... There was 471 subdirectories in the end.
I have solved the deletion of this with the help of move. I think that what I did falls into divide and conquer type of solving problems, but it was done totally manual.
What I did was to go pretty deep into the tree with Windows Explorer, copy the path, go to cmd, change dir and then move the subdirs to i:\fix\01-10
So, move worked, even when rd wouldn't. By "cutting the tree" like that, I could delete the "branches" that were not too long anymore.
And now to the point. Can someone come up with a way to put this logic in a batch? I think the scrip should be run at the top of such tree and then go as deep as the filesystem allows, move te rest upwards, delete the remaining tree, go to the moved directory, go as deep as the filesystem allows, etc. loop until cut to small enough pieces and then just do rd /s /q on them.
I have solved the deletion of this with the help of move. I think that what I did falls into divide and conquer type of solving problems, but it was done totally manual.
What I did was to go pretty deep into the tree with Windows Explorer, copy the path, go to cmd, change dir and then move the subdirs to i:\fix\01-10
So, move worked, even when rd wouldn't. By "cutting the tree" like that, I could delete the "branches" that were not too long anymore.
And now to the point. Can someone come up with a way to put this logic in a batch? I think the scrip should be run at the top of such tree and then go as deep as the filesystem allows, move te rest upwards, delete the remaining tree, go to the moved directory, go as deep as the filesystem allows, etc. loop until cut to small enough pieces and then just do rd /s /q on them.
Re: Batch to delete directory with path-too-long problem.
Someone has to reproduce a path that is too long, to test it.
I pass. Too lazy. Well, on second thoughts.
I didn't have any trouble deleting the folder it made though. It didn't create 471 folders.
Directory of m:\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one
30/05/2013 20:02 <DIR> .
30/05/2013 20:02 <DIR> ..
0 File(s) 0 bytes
Total Files Listed:
464 File(s) 64,421,391 bytes
10095 Dir(s) 19,088,896 bytes free
m:\>rd /s /q one
I pass. Too lazy. Well, on second thoughts.
Code: Select all
@echo off
:loop
md one
cd one
md two
cd two
goto loop
pause
I didn't have any trouble deleting the folder it made though. It didn't create 471 folders.
Directory of m:\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one\two\one
30/05/2013 20:02 <DIR> .
30/05/2013 20:02 <DIR> ..
0 File(s) 0 bytes
Total Files Listed:
464 File(s) 64,421,391 bytes
10095 Dir(s) 19,088,896 bytes free
m:\>rd /s /q one
-
- Posts: 18
- Joined: 02 May 2013 06:09
Re: Batch to delete directory with path-too-long problem.
Oh, the problem (the loop) was created using File Server Migration Wizard.
Re: Batch to delete directory with path-too-long problem.
thanks for the info.,you could also try long path tool. it helped me with error 1320 in Win 7.,
-
- Posts: 18
- Joined: 02 May 2013 06:09
Re: Batch to delete directory with path-too-long problem.
Hm, yeah... LongPathTool is not free... I know we can make batch file that will be free and open...
Re: Batch to delete directory with path-too-long problem.
I used a batch script to create some folders in XP:
it stopped at #85 with the message "file name or extension too long".
I removed it without problems "rd /s /q 1".
I created more subfolders with a third party file manager (SpeedCommander).
I could enter the folders until #88 with the "cd" command, for #89 I got the error message "path not found".
"tree" also stopped at #88:
"rd /s /q 1" could not remove this long path ("path not found", but the file manager did it.
Imo you can code a command line tool with C, Pascal ... (VB?) which can also remove such long paths.
Code: Select all
@echo off
:loop
set /a counter +=1
echo %counter%
md "%counter%" || goto:eof
cd "%counter%" || goto:eof
goto:loop
it stopped at #85 with the message "file name or extension too long".
I removed it without problems "rd /s /q 1".
I created more subfolders with a third party file manager (SpeedCommander).
I could enter the folders until #88 with the "cd" command, for #89 I got the error message "path not found".
Code: Select all
C:\1\2\3\4\5\6\7\8\9\10\11\12\13\14\15\16\17\18\19\20\21\22\23\24\25\26\27\28\29\30\31\32\33\34\35\36\37\38\39\40\41\42\43\44\45\46\47\48\49\50\51\52\53\54\55\56\57\58\59\60\61\62\63\64\65\66\67\68\69\70\71\72\73\74\75\76\77\78\79\80\81\82\83\84\85\86\87\88>
"tree" also stopped at #88:
Code: Select all
C:\1
└───2
└───3
└───4
└───5
└───6
└───7
└───8
└───9
└───10
└───11
└───12
└───13
└───14
└───15
└───16
└───17
└───18
└───19
└───20
└───21
└───22
└───23
└───24
└───25
└───26
└───27
└───28
└───29
└───30
└───31
└───32
└───33
└───34
└───35
└───36
└───37
└───38
└───39
└───40
└───41
└───42
└───43
└───44
└───45
└───46
└───47
└───48
└───49
└───50
└───51
└───52
└───53
└───54
└───55
└───56
└───57
└───58
└───59
└───60
└───61
└───62
└───63
└───64
└───65
└───66
└───67
└───68
└───69
└───70
└───71
└───72
└───73
└───74
└───75
└───76
└───77
└───78
└───79
└───80
└───81
└───82
└───83
└───84
└───85
└───86
└───87
└───88
"rd /s /q 1" could not remove this long path ("path not found", but the file manager did it.
Imo you can code a command line tool with C, Pascal ... (VB?) which can also remove such long paths.
-
- Posts: 18
- Joined: 02 May 2013 06:09
Re: Batch to delete directory with path-too-long problem.
Endoro, thank you for your valuable input!
Just to clarify - file manager that succeeded with deletion was SpeedCommander?
Just to clarify - file manager that succeeded with deletion was SpeedCommander?
Re: Batch to delete directory with path-too-long problem.
yes, of course. you can have a fully functioning test version to remove the annoying path.
Re: Batch to delete directory with path-too-long problem.
The problem is not with the number of directorys. Is about the length of the path.
256 is the limit of the path.
If you want bypass the limitation you need use unc notation appending this at the begin of path: \\?\
Example, currently I'm not in windows, but for example if you want do this:
and the length of the directory path is greater than 256 you can not do, but using unc notation you can:
256 is the limit of the path.
If you want bypass the limitation you need use unc notation appending this at the begin of path: \\?\
Example, currently I'm not in windows, but for example if you want do this:
Code: Select all
cd /d c:\
md aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccddddddddddddddddddddddddddddfffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
and the length of the directory path is greater than 256 you can not do, but using unc notation you can:
Code: Select all
md \\?\C:\aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccddddddddddddddddddddddddddddfffffffffffffffffffggggggggggggggggggggggggggggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
Re: Batch to delete directory with path-too-long problem.
carlos wrote:The problem is not with the number of directorys. Is about the length of the path.
256 is the limit of the path.
The OP did say that there were 471 folders, each of three characters.
FWIW I think backslashes are counted in the path limit too.
Re: Batch to delete directory with path-too-long problem.
Please accept my apologies for resurrecting this thread but I'd also like a sollution to this issue.
What we known conclusively is that a directory with a depth of more that 256 characters (slashes included) cannot be deleted by normal means. On the web you find people recommending 7-zip manager to delete, or using robocopy /mir command but sometimes these do not work, sometimes they do but is not guaranteed.
As now we have those hybrids that can run VBS and Powershell, and other languages as well. Isn't there something in VBS or Powershell that can be used to remove long paths?
What we known conclusively is that a directory with a depth of more that 256 characters (slashes included) cannot be deleted by normal means. On the web you find people recommending 7-zip manager to delete, or using robocopy /mir command but sometimes these do not work, sometimes they do but is not guaranteed.
As now we have those hybrids that can run VBS and Powershell, and other languages as well. Isn't there something in VBS or Powershell that can be used to remove long paths?
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: Batch to delete directory with path-too-long problem.
You could also use the "subst" commmand, to shorten the involved pathes.
penpen
penpen
-
- Posts: 1
- Joined: 15 Mar 2020 23:43
Re: Batch to delete directory with path-too-long problem.
Long Path Tool will let you easily delete, copy or rename long path files.
-
- Posts: 7
- Joined: 20 Feb 2020 06:40
Re: Batch to delete directory with path-too-long problem.
Long path tools or super copying programs that support long path names will help you in your issue and as a solution out of the box for the path names, are they all in subdir's or spread out all over the place? You could actually do the above for these also, however, if they're all over the place, creating 100+ separate jobs would be counterproductive. If they are within the same tree structure, create a batch that starts further down into the subdir, then you can exclude that in the batch file that copies the rest of the structure, if that makes sense. The switch to exclude a folder is /XD dir (so, it would look like /XD \\server\share\sub1\sub2\sub3) which will definitely shorten your path names.