How to

I wanted to delete a folder that contains thousands of files and folders (I’ve used Windows 2012 Server). If I use Windows Explorer to delete the folder (just in my case) then it takes ~4 minutes 30 seconds (not always, but often). Too long. Unfortunately, Windows Explorer is slow for this as it first scans the whole directory so that it can show the estimate and then copies everything into the recycle bin or not, if the directory is too big. Small tip: you can hold SHIFT key when you click option do delete files and Windows will not move any files to recycle bin.

I’ve started thinking if there is faster way in Windows to delete folders. I was experimenting with deleting files and folders using just Explorer and command line and here are the results.

Let’s say that the folder contains 56.2 GB size, 234 351 files and 29 756 folders:

size_and_amount_of_files

So, I’ve started deleting files using standard, built-in Explorer and after some while the results is 4 minutes 33 seconds.

deleting using windows gui

Next, I did the same but using command line:

deleting using windows cmd

and the result is 3 minutes 20 seconds.

deleting using windows cmd result

Conclusion

In this particular case using command line to delete whole folder content is faster around 35% than using Explorer. However, I strongly suppose it will be faster in most cases.

Batch script

@echo off
cls
echo Deleting directories
time /T
set DIR_LIST=(my_folder)

for %%i in %DIR_LIST% do (
    if exist %%i\nul (
        echo Deleting %%i folder
	rmdir /s/q %%i > nul
    ) else (
        echo Folder "%%i" doesn't exists
    )
)

time /T

Just specify folders in DIR_LIST environment variable and separate them by space. I’ve used here time /T to display the current time and measure deleting time. Just minutes, no seconds.

By the way, I found nice site where is an A-Z Index of the Windows CMD command line. Very useful.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Comments

You can leave a response, or trackback from your own site.

Before you add comment see for rules.

Leave a Reply

Your email address will not be published. Required fields are marked *

0f1f4h