Jump to content

Long Path Deleter


llewxam
 Share

Recommended Posts

Many times I have come across folders that Windows can not delete because the path length exceeds the maximum. Tools such as my Sync Tool that are UNC-aware can write paths that the file system "does not support", and you're stuck trying to dig your way to the end and delete things, or renaming the folders all to single-digit names in hopes of getting the path under 256 characters long...... annoying, and few good solutions are out there.

I came across a rather amusing method recently which uses RoboCopy to do the hard work. RoboCopy is fully UNC-aware, and the trick is to use it's mirror function. Someone built a batch file which creates a new folder in the Temp folder, and tells RoboCopy to mirror that empty folder to the one you can not delete, which causes RoboCopy to say "Hey, the files and folders in this folder don't exist in the other one, I better delete them all." When it is done, the batch file removes the temporary folder it created as well as the one you specify. Pretty clever, and at least I got a bit of a laugh at it... :)

Here is a simple GUI for the process, and the Zip file has the batch file and RoboCopy. The included version of RoboCopy is very old intentionally, as a newer version was not able to run on Server 2003, yet this older version has worked on every OS I have thrown it on. Also, once or twice the specified folder would wind up empty but not itself deleted, so I threw it in a loop to ensure it goes away.

Enjoy

Ian

FileInstall("delbat.bat", @TempDir & "\delbat.bat", 1)
FileInstall("robocopy.exe", @SystemDir & "\robocopy.exe", 1)

$Path = FileSelectFolder("Select the folder to be deleted", "")
$Confirm = MsgBox(4, "Confirm", Chr(34) & $Path & Chr(34) & @CR & "will be fully removed, and will not be recoverable from the Recycle Bin. Are you sure?")
If $Confirm == 6 Then
    For $a = 1 To 10
        ShellExecuteWait(@TempDir & "\delbat.bat", Chr(34) & $Path & Chr(34), "", "open", @SW_HIDE)
        If Not FileExists($Path) Then
            MsgBox(0, "Done", Chr(34) & $Path & Chr(34) & @CR & "has been removed.")
            Exit
        EndIf
    Next
    If FileExists($Path) Then MsgBox(48, "ERROR", $Path & @CR & "could not be removed. Make sure any open files/applications have been closed and try again.")
EndIf

LPDExtras.zip

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...