Auto delete in command prompt

daniel508

Distinguished
Aug 23, 2010
45
0
18,540
Hi guys. there's a folder that users scan things into. however this folder needs to be cleaned up on a regular basis. to do this, I have created a .bat file that will clear up all of the documents in that folder. there is also an auto answer of yes so that when it prompts, it automatically replies yes. however, I'd like this to delete items say 2 weeks old and older. is there a way to do this?
Thanks
 

kd0frg

Distinguished
Apr 16, 2010
220
0
18,710



you could use a perl script change DELOLD to how many days old from today say, 120 days old, delete it, 14 days (2 weeks) delete it.

[cpp]
#!perl -w
use strict;
usage() if (! @ARGV || $ARGV[0] =~ /\D/);
my $age = $ARGV[0];
my $dir = $ARGV[1] || '.';
while (<$dir/*>) { print 'unlink $_' if -M $_ > $age; }

sub usage {
print <<'EOF';
USAGE:
DELOLD 14 [c:\yourdirhere]
[/cpp]

so just save this code into a notepad, (remove the 1. 2. 3. from each line) then save as say.. well call it, cleanup.pl .. now download and install perl

http://www.activestate.com/activeperl/downloads

put cleanup.pl in a scheduled task to run every so often or put it in windows startup so it runs each time the computer boots? what ever you prefer
 

daniel508

Distinguished
Aug 23, 2010
45
0
18,540
this is going to be put on a server so I don't really want to install anything on there. I was hoping a simple .bat file would suffice?