How store modified date of file to variable?

December 18, 2010 at 15:19:03
Specs: Windows XP/Vista/7, Any/All
I have a file that is stored on a flash drive that is passed around the office every morning. The file contains updated info that needs to be on all systems. Here's what I'm needing to do via a DOS batch file:

1) Plug in flash drive into any computer system
2) Run batch file PCSetup.bat from the flash drive
2a) Batch file stores modified date of file %flashdrive%\UserInfo.txt to a variable %filedate%
3) Check the desktop of the current user for UserInfo.txt
4) If the current user doesn't have the file, the file needs to be copied to the desktop from the flash drive
5) If the current user has the file, then store the modified date of %userprofile%\Desktop\UserInfo.txt in a variable %userdate%
6) Compare%userdate% to %filedate% and if the desktop file is older than 1 day, then replace the file on the desktop with the more current one from the flash drive

I've been doing research on Google for over an hour now, and can't find any way to accomplish this via batch. Help?

See More: How store modified date of file to variable?

Report •

December 19, 2010 at 16:24:46
all the steps are easy (except no. one, of course. batchfiles can't plug things into
the computer!) except for number 6, becuse then you get into the issue of...
along with the attendant confusions and conflicts of DATE FORMATs.
There are tons of code written to handle date math, in various languages and in
native batch (I've written a couple myself, one batch and a better one using vbscript). vbscript has date math built in (dateadd, datediff functions), so it is the best way, but you have to have cscript.exe available to interpret the vbscript.
if you have access to vis.basic, it has those same functions, and you can compile
it. The keep-it-simple method would be to manually update the critical date in
the batchfile or in a squibfile, but then someone needs to know to do that every day.
The other option, IF the file is newer than one day old, and IF the file is the same as
the one on the flash, just write over the file. But i'm assuming that's not the case
or it would not be so critical to do this date math.
here's a vbscript version:
set xin=wscript.stdin
set cout=wscript.stdout
dim y,d(3)
set y=wscript.arguments
if a < 0 then wscript.quit
for i=0 to a
if a=0 then
end if
'use colon to interpret as time, else date
'sets defaults for date (diff in days) or time (diff in minutes)
if p>0 then s="n" else s="d"
'now allow overrides by token #1 if valid subset
if instr("dmwhns",lcase(d(0)))>0 then
end if
'-------- end of script

it has features you don't need but might want to leave in there.
to use it in batch:
for /f %%a in ('cscript dd.vbs %filedate%') do set ddif=%%a

i swapped the dates so you wouldn't have to change the sign from negative.

Report •
Related Solutions

Ask Question