Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello All,
using batch command how can i test if a PST file in drive C:\temp is newer than same file on H:\Temp and then perform an task based up that.
Basically:
IF c:\temp\file.pst has a later modified date than h:\folder\file.pst DO xxxxx
Thank you.

You can do this using vbScript quite easily.
save this in notepad as a .vbs file
Dim filesys, thefile, theFile2, createdate, createdate2
Set filesys = CreateObject("Scripting.FileSystemObject")
Set thefile = filesys.GetFile("path_to_file_1")
Set thefile2 = filesys.GetFile("path_to_file_2")
createdate = thefile.DateLastModified
createdate = replace(createdate,"/","")
createdate = replace(createdate," ","")
createdate = replace(createdate,":","")
createdate = replace(createdate,"AM","")
createdate = replace(createdate,"PM","")
createdate2 = thefile2.DateLastModified
createdate2 = replace(createdate2,"/","")
createdate2 = replace(createdate2," ","")
createdate2 = replace(createdate2,":","")
createdate2 = replace(createdate2,"AM","")
createdate2 = replace(createdate2,"PM","")
msgbox createdate & " " & createdate2
if createdate > createdate2 then
msgbox "file 2 is older than file 1"
else
msgbox "file 1 is older than file 2"
end ifThe script will check both files, get the modified date of both of them, strip out all useless date characters and then compare the two numeric strings. I'm sure there's a better way to strip the date or simply return just the time portion of it but I havent used vbscript for a while now, vb.net has screwed my logic from old school vb!

I don't think this works.
Suppose date1 = "11:00:00 AM"
and date2 = "10:00:00 PM"Then after that VBScript strips out the colons and the PM/AM indicators, it will leave date2 < date1 which is wrong.

Indeed, klint. And I find it much too complex; why convert a number into a complex string, just to see which number is bigger? A better version would be:
Dim filesys, With CreateObject("Scripting.FileSystemObject")
If .GetFile("path_to_file_1").DateLastModified > .GetFile("path_to_file_2").DateLastModified Then
msgbox "file 2 is older than file 1"
Else
msgbox "file 1 is older than file 2"
End If
End With

Thanks Razor. I wasn't sure if what you wrote was possible, because MSDN help doesn't say what the return type of DateLastModified actually is. It only shows example usage that treats it as a string.

Hi guys thank you for all your help.
My issue is that I need to compare these two files from a bat file.
My batch script backs up a bunch of folders with robocopy and I know robocopy will exclude files if they are the same but I will elaborate so maybe there is a solution out there.
PST files can be very large and thus take several minutes to copy over a 100Mbps network. So let’s say user Jenny has say 4 PST files in C:\PSTs each one of them 1 GB in size accounting for the past 4 quarters of 2008. Jenny only opens 4th quarter in outlook and seldom opens the other files although she wants to keep them with her because from time to time she needs to go back.
Now my script checks if outlook is open if it is it will give the user a message (still batch here) telling them that Outlook will be shut down in order to backup her PST file. Outlook will automatically start back up when it is done. Now this could mean that she has to stop working and wait and wait for the 75 or so Mbps until all the modified PST are copied to the network drive.
To solve the wait issue I came up with the “great idea” of programmatically creating a C:\Temp folder copying the psts (at 400 to 600 Mbps) to the temp location and then start outlook and continue copying in the background, this way Jenny can continue working 70% faster than before.
The problem now is that because C:\temp is new robocopy will copy ALL the psts to the new location which is taking forever every single time.
If I could only test the following programmatically.
IF any file in C:\PST is newer than the file in G:\PST then copy the file(s) from C:\PST to C:\temp
Once the only file that has changed is copied to C:\temp start outlook and then copy C:\temp\*.pst to the network drive.
I KNOW I’M ASKING FOR A LOT

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |