Computing.Net > Forums > Programming > Batch File to clean folders

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File to clean folders

Reply to Message Icon

Name: samcneal
Date: December 20, 2004 at 06:11:22 Pacific
OS: Windows 2003
CPU/Ram: Quad 4, 1 gig
Comment:

Anyone knows how to create a batch file to clean up a folder based on a certain number of days? I want to delete files older than 7 days but I don't know the syntax for date. I know how to delete files using the batch utility.


- Sonya



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: December 21, 2004 at 15:29:39 Pacific
Reply:

Hi
I wrote a batch for WinXP to delete files older than a certain number of days, as I'm english I guess than I would have to change the date variables in the batch file.
ie this command typed at the dos prompt on my system "date /t" produces "21/12/2004".
Your would produce "12/21/2004" is that correct if not what format doe's it produce.
I'm not familar with Windows 2003 so I think it might work ok on your system.



0

Response Number 2
Name: FishMonger
Date: December 21, 2004 at 21:55:28 Pacific
Reply:

Calculating past/future dates and differences between them is not an easy task for a batch file.

If you're interested, here's a Perl script that would be cleaner than the batch file. This uses the parent directory as its starting point and does a recursive desent into each subdir deleting any file that was modified 7 or more days ago.

#!perl -w

use strict;
use File::Find;

my $dir = 'path/to/parent/dir';

finddepth(\&file_be_gone, $dir);

sub file_be_gone {
    return if /^\.\.?/;
    if ((_M $_) >= 7) { unlink $File::Find::name; }
}


0

Response Number 3
Name: FishMonger
Date: December 21, 2004 at 22:05:41 Pacific
Reply:

Oops, I made a typo.

change:
   if ((_M $_)

to:
   if ((-M $_)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File to clean folders

Batch File to open and move .ttf fi www.computing.net/answers/programming/batch-file-to-open-and-move-ttf-fi/12043.html

batch file to call reg files? www.computing.net/answers/programming/batch-file-to-call-reg-files/8298.html

Batch file to stip folders www.computing.net/answers/programming/batch-file-to-stip-folders/10813.html