Can't delete folders where PATH is too long

Status
Not open for further replies.
J

Jeff T

OS: Windows XP Pro

I have a client who somehow got a ba-zillion folders created and now
can't delete them. I've read the Q articles Q180410 and Q157069 but
two methods described don't work because at the end of this path is a
set of folders that *does* have data. So I guess it's like the old
deltree command where you couldn't delete a folder unless it was
empty.

It's alright that the data be deleted as it is backed up but does
anyone know how to delete the long path even though there is data in
some of the outlying folders?

These two techniques do not work:

~ share the folder, then map a drive and delete from the mapped drive
letter.

~use the subst command to create a virtual drive and delete from
Windows explorer all folders underneath.

In the first solution, the drive won't map as Windows can't access the
outlying folders beyond 255 characters.

In the second solution a drive letter *is* created but you can't
delete any folder as Windows reports there is inaccessible data.

Is there another solution for removing these folders and data?

thanks

Jeff
 
J

Jeff T

Patty,

how would you go about using this command? i.e. from which folder, the
parent or further in? From a command shell within XP?

thank you
Jeff
 
Joined
May 8, 2007
Messages
1
Reaction score
0
"rd /s" Worked for me

Just wanted to let you know I had the same problem--could not delete from command line, because directory structure had somehow become too deep (Hey nice job Microsoft, thanks for letting me create a directory structure that is too long to be managed by Windows--maybe you should prevent this from happening in the first place!).

Anyway, using the remove directory command with subdirectory switch did the job:
rd /s nameOfDirectory

Best and kind regards
 
Joined
Aug 25, 2008
Messages
1
Reaction score
0
Has anyone tried the abtollc site? It sounds like quite a useful patch, but noscript blocks the site entirely, and I wonder if I should disable the blocking?
 
Joined
Mar 14, 2009
Messages
1
Reaction score
0
Don't bother with that abtollc site, it's pretty worthless to pay for something you can do for free.

Windows IT Pro has a good article and a batch file you can use that will fix this issue for you.

http://windowsitpro.com/article/art...lete-a-folder-that-returns-path-too-long.html

Basically it uses RoboCopy and you use a Batch file and it removes all the folders for you. I had a folder that was nested several thousands folders in (because of a copy issue I had). Creating the DelFolder.bat file worked great and fixed it in about 30 seconds (it had to delete a TON of nested folders/files).

I have scripted DelFolder.bat to delete a folder, even if the path is too long.

The syntax for using DelFolder.bat is:

DelFolder FolderPath

Where FolderPath is the path to the folder you wish to delete.

NOTE: DelFolder.bat uses RoboCopy.exe, which must be located in a folder that is in your PATH.

[size=+1]DelFolder.bat[/size] contains:
@echo off
if {%1}=={} @echo Syntax: DelFolder FolderPath&goto :EOF
if not exist %1 @echo Syntax: DelFolder FolderPath - %1 NOT found.&goto :EOF
setlocal
set folder=%1
set MT="%TEMP%\DelFolder_%RANDOM%"
MD %MT%
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%
endlocal
 
Last edited:
Joined
May 26, 2009
Messages
1
Reaction score
0
I tried the bat file but I get errors saying that it cant find the directory but it IS there!

I also get errors saying that directories aren't empty.. sigh.. will i have to manually empty all dirs? Eclipse made this problem for me :(
 
Joined
Aug 16, 2009
Messages
2
Reaction score
0
This cmd script works for me:

Code:
@echo off
  if _%1_==__ (
  echo Usage: %0 folderpath
  goto end
  )
  
  setlocal
  
  set i=%2
  if _%i%_==__ set i=0
  set /A i=%i% + 1
  
  del /Q /F %1\*
  
  for /D %%d in (%1\*) do (
  move %%d %i%_%%~nd
  )
  rd /Q %1
  
  for /D %%d in (%i%_*) do (
  call %0 %%d %i%
  )
  
endlocal
    
:end
 
Joined
Aug 16, 2009
Messages
2
Reaction score
0
Slightly refined:
Code:
@echo off

if _%1_==__ (
echo.
echo Usage: %0 folderpath
echo Deletes specified folder and all subfolders, even if the path depth
echo is larger than what CMD/Explorer will manage.
echo   folderpath - the folder to delete
echo.
goto end
)
 
setlocal

rem ** The full path of the folder to delete
set target_folder="%~f1"
set target_drive=%~d1

rem ** Create a temp folder on the same drive as the target folder (since moves within the same drive does not involve copying and traversing paths)
set tmp=%3
set del_temp_folder=nope
if {%tmp%}=={} set tmp=%target_drive%\temp_%RANDOM%
if not exist %tmp% (
md %tmp%
echo Will delete folder: %target_folder%
echo Will use temp folder: %tmp%
set del_temp_folder=yepp
pause
)

rem ** Create a prefix to use on moved folders to avoid name clashes
set i=%2
if {%i%}=={} set i=0
set /A i=%i% + 1

echo Level %i%, folder %target_folder%

rem ** Delete all files (non-directories) from the folder
del /Q /F %target_folder%\*

rem ** Move all subfolders to the tempfolder, and delete the now empty folder
for /D %%d in (%target_folder%\*) do (
move "%%d" "%tmp%\%i%_%%~nd"
)
rd /Q %target_folder%
 
rem ** Recursively repeat the above for all the moved subfolders
for /D %%d in (%tmp%\%i%_*) do (
call %0 "%%d" %i% %tmp%
)

rem ** Clean upp
if {%del_temp_folder%}=={yepp} (
rd /Q %tmp%
)

endlocal

:end
 
Joined
Sep 11, 2009
Messages
17
Reaction score
0
Better solution

I have a faster and easier solution.

If you have Vista or Win7 you're all set to go, or you're on XP then you need to download the Windows Resource Kit Tools installer. Basically you just need to have robocopy.

Make an empty folder say C:\temp
Then use robocopy to copy it to the folder that you can't delete say C:\TooDeep

robocopy C:\temp C:\TooDeep /E /MIR

The /MIR option makes robocopy mirror temp onto TooDeep, or in other words deleting extra files and folders.

Have fun :)
 
Joined
Sep 9, 2010
Messages
1
Reaction score
0
Java Application to delete directory

Go to this link http://www.osmstudios.com/Display.asp?Page=pathtoolong and after download If you have jdk installed then go to command prompt, cd to the location where the downloaded file(unzipped pathtoolong.zip file) exist and type java -jar nameofthejar(pathtoolong.jar).You can see the window where you delete the directory.
 
Joined
Sep 14, 2010
Messages
1
Reaction score
0
an easy solution

I was trying to delete a folder which was reporting as bing file protected or in use. I was going through it deleting it chunk by chunk and found that I had a file structure that was too long. All I had to do is move the embedded folder to my desktop and I was able to delete it from there.
 
Joined
Nov 24, 2010
Messages
1
Reaction score
0
dOSM said:
OSMstudios makes a handy little Java utility to take care of this problem.

http://www.osmstudios.com/Display.asp?Page=pathtoolong


This worked like a charm and it was free. Thank you!

FYI... What coused my problem in the first place, was using a command prompted and robocopy (robocopy /E /R:1 /B to copy windows user files to an external 1 tb HD. After letting it run over night the next morning the screen seemed to have pages of paths flying by. I stoped is and found it had used 250gb of space and only the directory AppData was showing up in the folder. I seems I had 250gb of paths; it took the Java program over an hour to delete the folder.
 
Status
Not open for further replies.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top