Sign in with
Sign up | Sign in
Your question

Auto delete in command prompt

Last response: in Windows 7
Share
December 1, 2011 9:07:17 AM

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
December 1, 2011 10:06:47 AM

daniel508 said:
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



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.

  1. #!perl -w
  2. use strict;
  3. usage() if (! @ARGV || $ARGV[0] =~ /\D/);
  4. my $age = $ARGV[0];
  5. my $dir = $ARGV[1] || '.';
  6. while (<$dir/*>) { print 'unlink $_' if -M $_ > $age; }
  7.  
  8. sub usage {
  9. print <<'EOF';
  10. USAGE:
  11. DELOLD 14 [c:\yourdirhere]


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
December 1, 2011 10:17:51 AM

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?
Related resources
December 1, 2011 10:22:57 AM

afraid i dont know enough about batch files to make something that complicated
December 1, 2011 11:48:58 AM

You can probably put something together from the snippets here.

http://stackoverflow.com/questions/51054/batch-file-to-...

There were quite a few post that came up when googling for this, and I believe there are a few examples in the above link that do not require installing any other software.
!