Delete Folder when Path Too Long

Sometimes you will try to delete a folder and get the error: PATH TOO LONG. This happens when there are files inside the folder where the full path is greater than 256 characters.


  1. Delete the folder by using its 8.3 short name. You can use dir /x <full path to file> to determine this
  2. Sometimes even the 8.3 short name is too long. Start renaming parent folders until the path is short enough.
  3. Use the following script to delete the folder

Script to Delete Folder when Path Too Long

This script will delete a folder even if the path is too long.

The script requires Robocopy, which comes with Vista and Windows 7, or you can download the exe for XP and Server 2003 and save it in C:\Windows\System32.

Save the script as DelFolder.bat, in C:\Windows\System32

Usage: DelFolder <full path to folder you wish to delete>

@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%