Best Command Line Tool to Delete Large Folder on Windows

I was working on a Windows 2016 server this week. I had to move some big folders to a different disk. After copying the folders, I needed to delete the big folders. I first tried to use the File Explorer to delete the folders, but it took too long to scan all the files and folders.

I then tried to use the command line del command to try deleting the folders. It worked only partially, got a lot of errors about files with long file name. I thought PowerShell might have better luck dealing with the long file name problem. I was wrong. The Remove-Item cmdlet cannot handle long file name.

I finally came across a post about using robocopy to delete folder and it works perfectly. The trick is to create an empty folder and use the /MIR flag to mirror the empty folder to the folder your want to delete.

The steps to delete a folder using robocopy:

  • Open up an elevated command prompt.
  • Change directory to where the folder you want to delete is.
  • Type the following commands (Replace the folder-name with the folder name you want to delete)
    mkdir empty
    robocopy empty folder-name /mir > nul
    rmdir empty
    rmdir folder-name

This post may contain affiliated links. When you click on the link and purchase a product, we receive a small commision to keep us running. Thanks.

Be the first to comment

Leave a Reply