Move files based on datetime in filename - Postet den (935 Views)
Senior Member
StephenD
Innlegg: 1044
1044
I'm trying to find a script in a batchfile that will move log files from one folder to another.
My files are in the named format 20110801.txt, 20110802.txt etc

I want to only move files older than 12 months and I can't use datecreated as all the files were moved to a new server and have the same datecreated/modified stamp from the migration process.
I have to use the date stamp in the file name as my trigger.
Any ideas?
   
 Sidestørrelse 
Postet den
Junior Member
pierretopping
Innlegg: 224
224
Hi,

I use robocopy(google it, its free) for that exact job. You can place a min date parameter to set what age files you want. PM me if you want a copy of the batch file.
Or maybe just use wildcards in the file name for now?
Pierre
Postet den
Support Moderator
Shaggy
Innlegg: 6780
6780
The way I'd do it in ASP would be to use the FSO to loop through all the files, convert each file name to date format, use datediff to compare that date to today's date and move the file if datediff is more than 12 months. Don't know much about batch files but the process, at least, should be the same.
Search is your friend “I was having a mildly paranoid day, mostly due to the
fact that the mad priest lady from over the river had
taken to nailing weasels to my front door again.”
Postet den
Forum Admin
HuwR
Innlegg: 20611
20611
you shouldn't need to convert them to datetime, if they are of the form yyyymmdd then you can just compare them as strings since

"20100101" < "20110101" is true for a string or a date smile
 
Du må legge inn en melding