Monday, August 8, 2011

Delete folder with long path

http://www.windowsitpro.com/article/jsifaq/jsi-tip-9651-how-can-i-delete-a-folder-that-returns-path-too-long-


When you attempt to delete a folder and receive PATH TOO LONG, you would normally Use the 8.3 short name, unless it has been disabled. Type dir /x . If the 8.3 path is too long, start renaming parent folders until the path is short enough.

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.

DelFolder.bat 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



1 comment:

Online Ustaad said...

I like this trick. This trick is good for users who love to play with technical ways. However, I have used “Long Path Tool” in this situation and it helped me easily and quickly. So this tool is best for those members who don't love to play with technical skills.