Job2 Street

Wednesday, December 25, 2019

Delete large folders in Windows super fast

How to delete large folders in Windows super fast

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

windows super fast delete large folders
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.
  1. Tap on the Windows-key, type cmd.exe and select the result to load the command prompt.
  2. 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.
  3. The command DEL /F/Q/S *.* > NUL deletes all files in that folder structure, and omits the output which improves the process further.
  4. Use cd.. to navigate to the parent folder afterwards.
  5. 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 OFF
ECHO Delete Folder: %CD%?
PAUSE
SET FOLDER=%CD%
CD /
DEL /F/Q/S "%FOLDER%" > NUL
RMDIR /Q/S "%FOLDER%"
EXIT
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.
delete folders quickly
Do the following to add the new batch file to delete folders quickly to the Windows Explorer context menu.
  1. Tap on the Windows-key, type regedit.exe and tap in the Enter-key to open the Windows Registry Editor.
  2. Confirm the UAC prompt.
  3. Go to HKEY_CLASSES_ROOT\Directory\shell\
  4. Right-click on Shell and select New > Key.
  5. Name the key Fast Delete
  6. Right-click on Fast Delete, and select New > Key.
  7. Name the key command.
  8. Double-click on default of the command key.
  9. Add cmd /c "cd %1 && delete.bat" as the value.
fast delete

No comments:

Post a Comment

K-Play

kPlaylist - get your music online

The player will show in this paragraph

2 3

IkimFM

speaker music speaker