You can mass delete files/directories with CMD or Powershell, but there are faster options

Some of these solutions might be risky, though.

Reading time icon 4 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

mass delete files windows

In Windows, there are ways to mass delete files/directories using all kinds of third-party software, like the ones we tested in our 2024 list.

However, the operating system is versatile enough to let users mass delete files and directories using CMD commands or Powershell commands to do so. For instance, this Reddit user knows this, and they developed two commands, one for CMD, and one for Powershell, that do the job.

If you want to try them, here they are.

The CMD command is this:

del /f /s /q “%USERPROFILE%\AppData\Local\Temp\*.*” >nul 2>&1

for /d %%x in (“%USERPROFILE%\AppData\Local\Temp*.*”) do @rd /s /q “%%x”

The Powershell command is this:

Get-ChildItem -Path “$env:USERPROFILE\AppData\Local\Temp” -Force | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue

Reddit user

However, the user wondered if there are faster options, as these commands don’t do the job fast enough. Needless to say, other users had a lot to say, and we gathered up some of the most popular responses. But if you’re curious about all of them, take a look at the Reddit thread.

The fastest way by far to mass delete files/folders is robocopy, which can be run using cmd.exe (may launch a second or two faster, execution time will be the same):

mkdir “%USERPROFILE%\empty” robocopy “%USERPROFILE%\empty” “%USERPROFILE%\AppData\Local\Temp” /mir rmdir “%USERPROFILE%\empty”

Or run using powershell.exe or pwsh.exe although it does not sound like PowerShell is needed here:

mkdir “$ENV:USERPROFILE\empty” & robocopy “$ENV:USERPROFILE\empty” “$ENV:USERPROFILE\AppData\Local\Temp” /mir rmdir “$ENV:USERPROFILE\empty”

Now, you might run into issues here due to files being in use

Reddit user

However, someone quickly added that using robocopy can be risky:

Be very careful with robocopy using /mir. Witnessed my partner in crime mirroring a large production file server one day to its new home on a schedule that had been running for a couple of weeks. He cut over to the new home over and deleted the source. Robocopy deleted all of production instantly. He turned white right before my eyes as he realised what had happened. Thank God we had shadow copies running. Fastest major recovery I have ever witnessed. Within 5 (or less) minutes all production was back. We never spoke of this again. But I am super careful with robocopy and the /mir switch.

Reddit user

Others were also successful in mass deleting files on Windows using dotnet:

I looked at deleting some huge folders (12Gb, 75k files, 7k folders) from a script a couple of years ago and settled on this dotnet call.

[System.IO.Directory]::Delete( $Folder.Fullname, $true )

It’s fast on a remote machine since it doesn’t enumerate locally. I’m not sure how it fits your use case. It does delete the base folder. You might be able to recreate it, or it might autocreate when used. Also, temp folders can have open files, not sure what happens there.

Reddit user

Others had other ideas:

Without putting it all in a scriptblock for Measure-Command, I do not know.

I do know the directory you give is 

$env:TEMP or %TEMP% 99% of the time. It is located in %LOCALAPPDATA% or $env:LOCALAPPDATA.

I also know you don’t need to get-childitem. You could just 

Remove-Item "$($env:TEMP)\*" -Recurse -Force or del /f /s /q %TEMP%

Also, /s takes care of all the subdirectories so you don’t need but the one command to do the same thing as bot commands and the loop.

Reddit user

And, ultimately, someone also used this:

Script C would be faster

Cd /d “%USERPROFILE%\AppData\Local\Temp\” rd /s /q .

This gets rid of the extra enumerations that the for loop you have in the command prompt version. It will throw an error at the end because you cannot delete the folder you are in. Command prompt will always be faster than powershell cmdlets because you have to build a file object as there is no native cmdlet that just builds a file path as a string. It takes time getting the added info like file size, creation date, etc. and creating said object. You will definitely see a difference if the number of files are in the five digits or higher. I use to maintain folders and files that needed deletion/archiving on a daily basis that were in the high 6 low 7 digits and this was usually the deletion solution that was fastest.

Reddit user

Once again, make sure to check the Reddit thread for other answers, as the post was made only hours ago, so there is a good chance more users will contribute to it.

More about the topics: file management tools