Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Move files based on datetime in filename
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

StephenD
Senior Member

Australia
1044 Posts

Posted - 10 September 2011 :  23:17:17  Show Profile  Send StephenD a Yahoo! Message  Reply with Quote
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?

pierretopping
Junior Member

United Kingdom
224 Posts

Posted - 11 September 2011 :  16:02:23  Show Profile  Visit pierretopping's Homepage  Reply with Quote
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

Edited by - pierretopping on 11 September 2011 16:03:53
Go to Top of Page

Shaggy
Support Moderator

Ireland
6780 Posts

Posted - 12 September 2011 :  07:56:35  Show Profile  Reply with Quote
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.”
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20593 Posts

Posted - 12 September 2011 :  08:24:32  Show Profile  Visit HuwR's Homepage  Reply with Quote
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

MVC .net dev/test site | MVC .net running on Raspberry Pi
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000 Version 3.4.07