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 <full path to file>. 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
set folder=%1
set MT="%TEMP%\DelFolder_%RANDOM%"
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.