Computer Hope

Microsoft => Microsoft Windows => Windows XP => Topic started by: andybeanland on July 01, 2005, 02:12:11 AM

Title: Batch to look at file creation date
Post by: andybeanland on July 01, 2005, 02:12:11 AM
Hello,

I'm trying to write a batch file (an additional to the users logon script) to find the modified date of a file, then find the difference between todays date and if the difference is greater than 100 days run a certain piece of software.

I'm sure this is fairly easy, but I'm pretty new to batch files. All I've managed to do so far is to output todays date to a text file. I think you can get the creation date using the "DIR filename", but this will need to be trimmed and I'm not sure how to do that in batch files.

Any help would be much appreciated

Thanks for your help
Title: Re: Batch to look at file creation date
Post by: Sidewinder on July 01, 2005, 05:21:11 AM
There are three dir switches available for dates:

/ta - date accessed
/tc - date created
/tw- date written

Calculations in batch files can be done with the set /a statement. That  said, date calculations are cumbersome and usually involve a long series of hardcoded IF statements.

A better tool would be Windows Scripting (free and installed on Windows machines since Win95C) which has built in date functions for just the purpose you need.

http://www.microsoft.com/technet/scriptcenter/default.mspx

Good luck. 8)