Subscribe to Windows IT Pro
August 19, 2005 12:00 AM

JSI Tip 9651. How can I delete a folder that returns PATH TOO LONG?

Windows IT Pro
InstantDoc ID #84207
Rating: (29)


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
setlocal
set folder=%1
set MT="%TEMP%\DelFolder_%RANDOM%"
MD %MT%
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%
endlocal



Related Content:

ARTICLE TOOLS

Comments
  • JoshuaReen
    2 months ago
    Mar 02, 2012

    I have used <a href="http://longpathtool.com/">Long Path Tool</a> in this situation and it helped me easily and quickly.

  • Stacy Spear
    6 months ago
    Nov 26, 2011

    Hi Peter, the script is making a new empty directory and then using Robocopy's mirror function to mirror it, essentially deleting all the files. It may run into issues if the structure is deep enough, but mostly works great.

  • Peter N
    7 months ago
    Oct 09, 2011

    The syntax for robocopy is
    ROBOCOPY source destination [file [file]...] [options]
    so it seems like

    set folder=%1
    set MT="%TEMP%\\DelFolder_%RANDOM%
    RoboCopy %MT% %folder% /MIR

    has the source & destination reversed?
    Am I correct?

  • Arnold
    10 months ago
    Jul 28, 2011

    Thank you for this helpful tool. It works perfect!!! Good job guys

  • kevinfitzroel
    1 year ago
    Jan 08, 2011

    Thanks for the tip. It was awesome and worked GREAT. The other program noted above costs $20 so you saved me the money. Thanks.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.