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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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
...
Answered 06/02/2011 by: smoky
Yellow Belt

Please log in to comment
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
Answered 06/03/2011 by: anphi
Orange Belt

Please log in to comment
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
Answered 06/03/2011 by: spartacus
Black Belt

Please log in to comment
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).
Answered 06/04/2011 by: VBScab
Red Belt

Please log in to comment
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
Answered 06/04/2011 by: anphi
Orange Belt

Please log in to comment
0
Thanks once again for the script..

the script is working like a charm...


regards

Aneesh
Answered 06/07/2011 by: anphi
Orange Belt

Please log in to comment
Answer this question or Comment on this question for clarity