i've been googling the last couple of days for a solution to my problem. There seems to be a ton of questions asked on this topic but somehow they are not working for me or (most likely) i'll be doing something wrong.
Const OverwriteExisting = True
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim FSO, MyFile, FileName, strFileName, strCopyTo
Set FSO = CreateObject("Scripting.FileSystemObject")
strFileName = "C:\......SourceFolder\SourceFile.html"
strCopyTo = "T:\....DestinationFolder\"
FileName = "T:\........\autorun.inf"
If FSO.FileExists(strFileName) Then
FileSystemObject.CopyFile strFileName, strCopyTo, True
'FSO.CopyFile strFileName, strCopyTo, OverwriteExisting
Else
For i = 1 to 3
If FSO.FileExists(strFileName) Then
FileSystemObject.CopyFile strFileName, strCopyTo, True
else
WScript.sleep 1000 '1000 milliseconds
End if
Set MyFile = FSO.OpenTextFile(FileName, ForAppending, True, TristateTrue)
' Write to the file.
MyFile.WriteLine "Attempt " & i & " - " & Now
MyFile.Close
Next
End If
What i'm trying to do is copying a file from the source folder located on C:\ to a shared network drive called T:. So i started the script with checking if the file exist, if it exists than it will have to copy it to the destination folder. If not i would like to try 3 more times with each at least 1 second a part from each other. for that i'm using the FOR method and WScript.sleep function. And if it didn't exist i'm writing it to a file.
Everything is working fine, except for the most important thing, the file even though it does exist it does not get copied.
I've checked the attributes on the origin and destination file, as according to google, the read-only attribute would prevent the file from being copied even when in the copy function "overwrite" is set to TRUE.
So i do not know where to look right now and would greatly appreciate any help.
Thanks Philippe
FileSystemObject. Problem is, when you created your object, you didn't call itFileSystemObject; you called itFSO. Trying turning onOption Explicitto avoid these sorts of problems.