When you delete huge folders in Windows, you will notice that the process takes quite a bit of time to complete.
I keep backup folders of Ghacks locally on a platter-based drive, and these folders come close to 30 Gigabytes in size with more than 140,000 files and 350 folders.
When I need to delete them again, it takes a long time if I run the delete operation in Windows Explorer. First thing that happens is that Windows runs calculations which in itself may take a very long time to complete.
Then when the actual deleting takes place, Windows analyzes the process and posts updates to the file operation window.
It may take ten or twenty minutes, or even longer, to delete a large folder using Explorer on Windows devices.
How to delete large folders in Windows super fast
If you run delete commands from the command line instead, you will notice that the operation completes a lot faster. You may notice that the operation needs just a fraction of time that the same operation requires when you run it in Explorer.
Matt Pilz, who wrote about this back in 2015 saw a reduction from 11 minutes to 29 seconds, which made the command line operation more than 20 times faster than the Explorer option.
The downside to this is that it requires use of the command line. Matt suggested to add the commands to the Explorer context menu, so that users could run them in Explorer directly.
The two commands that users require are Del, for deleting files, and Rmdir, for removing directories.
- Tap on the Windows-key, type cmd.exe and select the result to load the command prompt.
- Navigate to the folder that you want to delete (with all its files and subfolders). Use cd path, e.g. cd o:\backups\test\ to do so.
- The command DEL /F/Q/S *.* > NUL deletes all files in that folder structure, and omits the output which improves the process further.
- Use cd.. to navigate to the parent folder afterwards.
- Run the command RMDIR /Q/S foldername to delete the folder and all of its subfolders.
The commands may require some explanation.
DEL /F/Q/S *.* > NUL
- /F -- forces the deletion of read-only files.
- /Q -- enables quiet mode. You are not ask if it is ok to delete files (if you don't use this, you are asked for any file in the folder).
- /S -- runs the command on all files in any folder under the selected structure.
- *.* -- delete all files.
- > NUL -- disables console output. This improves the process further, shaving off about one quarter of the processing time off of the console command.
RMDIR /Q/S foldername
- /Q -- Quiet mode, won't prompt for confirmation to delete folders.
- /S -- Run the operation on all folders of the selected path.
- foldername -- The absolute path or relative folder name, e.g. o:/backup/test1 or test1
Creating a batch file and adding it to the Explorer context menu
If you don't need to run the command often, you may be perfectly fine running the commands directly from the command prompt.
If you do use it frequently however, you may prefer to optimize the process. You may add the command to the Explorer context menu, so that you can run it from there directly.
First thing you need to do is create a batch file. Create a new plain text document on Windows, and paste the following lines of code into it.
ECHO Delete Folder: %CD%?
DEL /F/Q/S "%FOLDER%" > NUL
RMDIR /Q/S "%FOLDER%"
Save the file as delete.bat afterwards. Make sure it has the .bat extension, and not the .txt extension.
The batch file comes with a security prompt. This provides you with options to stop the process, important if you have selected the context menu item by accident. You can use CTRL-C or click on the x of the window to stop the process. If you press any other key, all folders and files will be deleted without any option to stop the process.
You need to add the batch file to a location that is a PATH environmental variable. While you may create your own variable, you may also move it to a folder that is already supported, e.g. C:\Windows.
Do the following to add the new batch file to delete folders quickly to the Windows Explorer context menu.
- Tap on the Windows-key, type regedit.exe and tap in the Enter-key to open the Windows Registry Editor.
- Confirm the UAC prompt.
- Go to HKEY_CLASSES_ROOT\Directory\shell\
- Right-click on Shell and select New > Key.
- Name the key Fast Delete
- Right-click on Fast Delete, and select New > Key.
- Name the key command.
- Double-click on default of the command key.
- Add cmd /c "cd %1 && delete.bat" as the value.