General discussion

Locked

Script that compare data file creation

By slava ·
How to create a script to compare the data
file creation?

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Script that compare data file creation

by Steve Durbin In reply to Script that compare data ...

Assuming you mean "date of file creation" of two files, then a simple way is to use VBS and the FileSystemObject DateCreated property. Here's a
quick-and-dirty script to give an ERRORLEVEL return depending on the date compared:

Function getcreated(fname)
dim f
if myFSO.FileExists(fname) then
getcreated = myFSO.GetFile(fname).DateCreated
else
wscript.echo "ERROR: File '" + fname + "' does not exist"
wscript.quit(1)
end if
end Function

Dim myFSO, myArgs, fname, dt1, dt2
set myArgs = WScript.Arguments
if myArgs.Count <> 2 then
Wscript.Echo "Usage: [File1] [File2]"
WScript.Quit(1)
end if
set myFSO = CreateObject("Scripting.FileSystemObject")
dt1 = getcreated( myArgs(0) )
dt2 = getcreated( myArgs(1) )
if dt1 = dt2 then
WScript.Echo "Same date"
WScript.Quit(0)
end if
if dt1 > dt2 then
WScript.Echo "First file newer"
WScript.Quit(2)
else
WScript.Echo "Second file newer"
WScript.Quit(3)
end if

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums