/build/static/layout/Breadcrumb_cap_w.png

Need a script to compare the dates inside a text file

Hi Colleagues,

I am a beginner in the scripting and the packaging field.I am stuck up in the below scenario.

I have 2 text files in which only today's date is mentioned (1/6/2011). One text file is in the server and the other one is in the local machine.
Now I need a script to check the dates, so that if there is a difference in the dates, I want to copy the contents from the server to the Local machine.

I made a basic script, but I am getting the error "Object doesn't support this property or method"

The code is:

Const ForReading = 1
Dim fso, txtFile1, txtFile2
set fso =CreateObject("Scripting.FilesystemObject")
set txtFile1 = fso.OpenTextFile("Server path", ForReading)
set txtFile2 = fso.OpenTextFile("Localmachine path", ForReading)

if txtFile1<> txtFile2 then
msgbox "Success" (just for checking the dates)
end if


Hoping you guys will be able to assist in this scenario...

Thanks in advance

regards

Aneesh

0 Comments   [ + ] Show comments

Answers (6)

Posted by: smoky 12 years ago
Yellow Belt
0
In order to compare dates, instead of

if txtFile1<> txtFile2 then


you can use fso.GetFile().DateLastModified or fso.GetFile().DateCreated, i.e.:


If fso.GetFile("Server path").DateLastModified <> fso.GetFile("Localmachine path").DateLastModified Then
...
Posted by: anphi 12 years ago
Orange Belt
0
Hi Smoky,

thanks for the reply and the code

but here the issue is, client's doesn't want the time stamp to be checked.....they want the date inside the text file(server location) to be checked and compared with the date mentioned in the text file in the local machine..

regards

Aneesh
Posted by: spartacus 12 years ago
Black Belt
0
Firstly, your post should ideally been put in the Scripting forum rather than Package Development, but I appreciate you are new here.

The following code should do it once you replace "Server path" and "Localmachine path" with valid paths, of course

Const ForReading = 1
Dim fso, txtFile1, txtFile2
Dim ServerDate, ClientDate

set fso =CreateObject("Scripting.FilesystemObject")
set txtFile1 = fso.OpenTextFile("Server path", ForReading)
set txtFile2 = fso.OpenTextFile("Localmachine path", ForReading)

ServerDate = txtFile1.readall
ClientDate = txtfile2.readall

If ServerDate <> ClientDate Then
msgbox ("Dates Different")
Else
msgbox ("Dates are the same")
End If

txtfile1.close
txtfile2.close

set fso = Nothing

Note that I haven't added any error checking which you should seriously consider adding yourself, for example how would you handle the server being unavailable for instance ?
Regards

Spartacus
Posted by: anonymous_9363 12 years ago
Red Belt
0
I haven't added any error checkingYou (the OP) should also appreciate that Graham has posted something for you to progress with, rather than use "as is". For example, ReadAll loads the entire file into the text stream. If your dates are on discrete lines, the comparison will most likely always be resolve to False. Also, the error-trapping you add should ensure that the strings you compare actually convert to the Date variable type (using CDate).
Posted by: anphi 12 years ago
Orange Belt
0
Thank you for your valuable inputs, spartacus and VBScab

I will try it out and will let you know if it works

Also in future, I will use the Scripting forum in case of any queries....thanks once again for the guidance

regards

Aneesh
Posted by: anphi 12 years ago
Orange Belt
0
Thanks once again for the script..

the script is working like a charm...


regards

Aneesh
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ