views:

370

answers:

2

Each night I need to do work on a folder 36 days old from the current date. I have a system that writes files to a daily structure like below. I need to keep 35days worth on the local disk and so each night I need to archive off the 36th day. Here is the kicker... There are approx 2 million files per day, so I cannot efficiently scan the whole 2009 folder and only move files older than 35 days. What I need to do is though a batch script determine the path of the folder that is 36days old and then apply my archive logic. I have scripts to determine but having trouble doing the determination to 36 days old. In a pinch I can use perl if there is not a batch way to do this. --Shawn

Folder structure is like this:

2009\07\01
2009\07\02
2009\07\03
.
.
.
2009\08\01
2009\08\02
2009\08\03

@EDIT: Helen's great answer has me 99% of the way there. My only problem is that the month and day out of the vbs is not padded with a zero which i have to deal with in the folder structure. Does anyone have an easy way to pad in a leading 0 if the day or month is less than 10?

Here is what I am doing so far:

for /F "tokens=1-3 delims=/" %%x in ('cscript //nologo get36thday.vbs') do (
   SET YYYY=%%z
   SET MM=%%x
   SET DD=%%y)

except %MM% ends up being 7 instead of 07

+1  A: 

The batch option is pretty wicked you will need to calculate which month it is then based of of that run a while loop counting down the days. I would high recommend perl as it would be a few lines of code

using the DateTime module from CPAN

http://search.cpan.org/dist/DateTime/lib/DateTime.pm

my $dt = DateTime->now->subtract(days => 36);
george9170
A: 

The batch way to determine the date would be too compilcated; it's much easier to use a script for that. Sorry, no Perl sample but a VBScript one:

WScript.Echo DateAdd("d", Date, -36)

You can call this script from a batch file and read the calculated date like this:

for /f %%d in ('cscript //nologo datediff.vbs') do set dt=%%d
Helen