Hi..
I have some code that I am working on that I am having a little problem with...
I have 2 x files.. SrcFile and DestFile. I have to check if the SrcFile and the DestFile have the same date stamp. If they do, then the script should exit, if not the source file will be written as the destination file, overwriting any existing file...
The script I have come up with is:
The problem that I am having is that the DateCreated is too accurate (i.e. it reports the time as well as the date) so the files need to be written at exactly the same time for the script to pick up that they are the same. This method would work if I could MIRROR the file rather than copy it, as it would then copy the same created date and time... is there a syntax for that?
I though about using:
But I am not sure if this would be accurate enough.. alternatively I suppose that I could try a binary/CRC check of some description???
The only other thing that I can think of is to:
1: mirror all files with robocopy, this gives a starting point
2: the script above should confirm that files are the same
3: any new files at the source, would initiate a robocopy script to re-mirror the src to the dest..
This is a bit dirty tho imo.. I would prefer to work out a solution within 1 script rather than 2. The script would also be run as part of a DTS package (SQL2K) so again, if this can be done without copying additional files onto the live sql server, that would be the preferred solution.
Any ideas are appreciated..
Ta :¬)
I have some code that I am working on that I am having a little problem with...
I have 2 x files.. SrcFile and DestFile. I have to check if the SrcFile and the DestFile have the same date stamp. If they do, then the script should exit, if not the source file will be written as the destination file, overwriting any existing file...
The script I have come up with is:
Code:
Const OverwriteExisting = True
Dim objSrcPath
Dim objDestPath
Dim objSrcFile
Dim objDestFile
set objFSO = CreateObject("Scripting.FileSystemObject")
'Sets Source path
set objSrcPath = objFSO.GetFolder("\\Servername\Sharename")
'wscript.echo objSrcPath
'Sets Destination path
set objDestPath = objFSO.GetFolder("\\Servername\Sharename\Foldername")
'wscript.echo objdestpath
'Sets Source file name
set objSrcFile = objFSO.GetFile (objSrcPath & "\Filename.TST")
'wscript.echo objsrcfile
Set objDestFile = objFSO.GetFile (objDestPath & "\Filename.TST")
If objFSO.FileExists(objSrcFile) Then 'If Source file exists
If DateDiff("d", (objSrcFile.DateCreated), (objDestFile.DateCreated)) <> 0 Then 'check the date stamp
wscript.echo objsrcfile.DateCreated
wscript.echo objdestfile.DateCreated
wscript.echo "files Don't have the same date stamp"
objFSO.CopyFile objSrcFile, objDestFile, OverwriteExisting
'If source and dest files do not have the same date stamp copy the file.
Else
wscript.echo objsrcfile.DateCreated
wscript.echo objdestfile.DateCreated
wscript.echo "Files are the same"
End If
End If
The problem that I am having is that the DateCreated is too accurate (i.e. it reports the time as well as the date) so the files need to be written at exactly the same time for the script to pick up that they are the same. This method would work if I could MIRROR the file rather than copy it, as it would then copy the same created date and time... is there a syntax for that?
I though about using:
Code:
If DateDiff("d", (objSrcFile.DateCreated), Date) <> 0
But I am not sure if this would be accurate enough.. alternatively I suppose that I could try a binary/CRC check of some description???
The only other thing that I can think of is to:
1: mirror all files with robocopy, this gives a starting point
2: the script above should confirm that files are the same
3: any new files at the source, would initiate a robocopy script to re-mirror the src to the dest..
This is a bit dirty tho imo.. I would prefer to work out a solution within 1 script rather than 2. The script would also be run as part of a DTS package (SQL2K) so again, if this can be done without copying additional files onto the live sql server, that would be the preferred solution.
Any ideas are appreciated..
Ta :¬)