Reputation: 1082
I apologize if this has been addressed before, but I've been unsuccessful in searching online for this answer.
We have a situation where we're syncing a local file to a network file, as per dummied down code below. E.g., if the network file exists, copy it to the local drive. If the network file is non-existent, then delete it from the local drive.
My question is, do I require some delay/test between the Kill
line and the Filecopy
line? So far, testing hasn't turned up any problem, but I'm still a bit unsure if this is sufficient.
Sub copyFile()
Const SFile As String = "N:\Test.txt"
Const tFile As String = "C:\Test.txt"
On Error Resume Next
Kill tFile
On Error GoTo errTrap
FileCopy SFile, tFile
errTrap:
End Sub
Upvotes: 1
Views: 400
Reputation: 834
I think your code is good, you can add error handler, when FileCopy error.
Sub copyFile()
Const SFile As String = "N:\Test.txt"
Const tFile As String = "C:\Test.txt"
On Error Resume Next
Kill tFile
On Error GoTo errTrap
FileCopy SFile, tFile
exit sub
errTrap:
'do something when FileCopy Error
End Sub
Upvotes: 2