How can I batch delete all files of a certain type in a folder newer than a certain date on Windows?

So Google Music decided to download about half of my uploaded music library to my local music library when I told it to download my purchased music, so now I have a bunch of MP3s I need to delete automatically.

Can I get any help here? I'm not so great with batch script.


Solution 1:

You can use forfiles

forfiles /p g:\music /d -30 /c "cmd /c del @file"

This will delete any file older than 30 days.

Read about forfiles syntax here

If it's not there in your system, download forfiles from MSFT's Reskit ftp

Solution 2:

For another command script way to do this, using JP Software's TCC/LE, simply use date ranges and the del command:

del /[d2011-12-19] *.mp3

Yes, you can do the last 30 days, too:

del /[d-30] *.mp3

Further reading

  • Jonathan de Boyne Pollard (2003,2007). Performing some commonly desired tasks with JP Software's command interpreters.. Frequently Given Answers.