Bat File To remove files

So you want to delete files in a folder that are X amount of days old..

You would think it is not that hard, I did !! but it took me a while to find something that would do it, as I could not figure out how to get a bat script to work. But I found a great little program that does this well….. It is called obsolete and you can get it here.

So you will be able to create a .bat program that will call the program that will look something like this. You can then use a scheduler to set up times for it to run.

c:\obsolete\obsolete.com -s -HSW 7 days *.* c:\testbat\temp\

Of course you will need to add your paths to the line…So this line will delete any files in the c:\testbat\temp\ that are older than 7 days.

Usage: obsolete [flags] age [-f] pattern [dir]

Will recursively remove all files which older than ‘age’ which match ‘pattern’.
Recursive scan starts from the current working directory or from ‘dir’ if
specified. ‘age’ is a sequence of pairs where N is an optional number
and ‘unit’ is seconds, minutes, hours, days, weeks, moths or years. ‘flags’ are
one or more flag characters preceded by “- optionally followed by “+” for
turning flag on (default), or “-” for turning it off.

FLAGS -h Print this message and exit
-H+ Remove hidden files too -R- Do not recurse into subdirectories
-S+ Remove system files too -W+ Remove write protected files too
-i+ Ask before removing file -I+ Ask before overriding write protect
-s Silent: don’t list files -n Do nothing: just list files

EXAMPLES
obsolete 2 weeks *.tdk c:\ Remove all drive C: 2 weeks old .tdk files
obsolete -R- 2 days *.bak Remove 2 days old .bak files from current dir obsolete day *.* \brief\backup Remove day old files from backup dir
obsolete -n 3 years *.exe \bin List all 3 years old .exe files in \bin
obsolete -s -HSW second *.@@@ \ Silently remove ALL (junk?) .@@@ files

Works great enjoy.

 

 

Be the first to comment

Leave a Reply