I sometimes delete masses of files on multiple computers with the Windows command line, with the DEL
command, and on some the function is verbose (i.e. outputs the files it deletes as it goes), while on others it's not the case. Is there a way to force the command line utility to always display its progress?
2 Answers
Both the del and erase commands will be silent unless you include the /s argument to delete all files in all subdirectories.
One option is to simply delete the files one by one. Let's say you want to delete everything in the temp folder:
for /f "tokens=*" %A in ('dir /s /b "%TEMP%"') do del /Q "%A"
That will take a while to start up against 2 million files as it will need to list them first and then delete them one by one.
Another option is to use Robocopy and have it mirror an empty directory to delete the files you want. You will get verbose output as each file is deleted. Start with an empty directory (c:\empty) and run something similar to the following:
robocopy c:\empty c:\dir_with_files_to_be_deleted *files_you_want_to_delete.* /mir /v
Or, if you just want to delete all files in a single directory:
robocopy c:\empty c:\dir_to_empty /mir /v
If you're deleting a whole directory, use rd/s/q
(rmdir /s /q
) instead.
-
Thanks, it is useful in some cases although right now I'm trying to delete certain files in a folder that contains over 2 million files.– YnhockeyDec 23, 2014 at 8:53
-
This is faster probably because it does not echo each delete on the console. Jun 20, 2021 at 16:09