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
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)
Please log in to answer
Posted by:
smoky
13 years ago
Posted by:
anphi
13 years ago
Posted by:
spartacus
13 years ago
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
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
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
13 years ago
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
13 years ago
Posted by:
anphi
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.