Find and Remove All Non-Empty Directories with Windows Command Prompt

It so happened that one of my test applications started to generate loads (>50) of tmpxyz folders with some temp data inside and failed to remove them afterwards. 

This behavior causes my Windows temp folder to be overfilled with data which’s no longer needed. My app runs once every half an hour, and at the end of the day I end up having several hundreds of tmp folders created. 

Here’s how I managed to get all those non empty folders removed with a command prompt:

> cd C:\Windows\Temp
> forfiles /M tmp* /C "cmd /C rmdir /S /Q "@file"

Here’s a .bat file to make this job automated:

@echo off
cd C:\Windows\Temp
forfiles /M tmp* /C "cmd /C rmdir /S /Q "@file"