By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Script to delete files older than N days?

I'm looking for a TCC script to delete all files older than N days which match a given filename pattern.

Surlely this wheel has been invented already. Thanks if you can provide it.
Edited to add: I’ve just realised that this was posted in the TCC/LE forum, I’m not sure if LE supports ranges, so apologies if it doesn’t, I don’t have a copy of LE to test it, and this reply won’t help you if ranges aren’t supported.

The DEL command supports date ranges:

If you’re just wanting to clear out old files from one directory then a script is probably overkill - just issue the command from the prompt, or maybe create an alias if you'll want to do it again in a few weeks or months. If you want to do it over multiple directories then it might be worth writing a batch file.

Do be careful with this though, test your DEL command with the /N option to make sure you are deleting the files you expect, and it’s always best to have a backup that you can restore if it goes wrong.
Thanks for the reply. It was my mistake to post in the TCC/LE section. I don't visit here often and am not familiar with the forum structure.

I will be running this command periodically to clear out old Quicken backup files which accumulate at the rate of one per day.
I also use Quicken.

I have my maximum number of backup copies set to 5.

Might be easier just to change this number, instead of running a batch file to remove them.


If you want to delete the files with a batch file;
@echo off
:: Keep last n days of backups
set Days2Keep=7
:: Change this to the location of your files
cdd C:\Users\jlcav\OneDrive\Documents\Quicken\BACKUP
:: How many backup files are older than %Days2Keep?
ffind /Q /![d-%Days2Keep] *.qdf-backup
iff %_ffind_files gt 0 then
  echo _ffind_files: %_ffind_files
  :: Show the backup files that are older than %Days2Keep days.
  dir *.qdf-backup /![d-%Days2Keep]

Last edited:
Thanks for the script.

In addition to automatic backups, I perform a manual backup after every Quicken session with the date in the filename. So they do accumulate.