Reputation: 416
I have a little Windows VB front end to a Robocopy command. Here is the line of code that passes the parameters to Robocopy:
.StartInfo.Arguments = """" & txtCopyFrom.Text & """ """ & txtCopyTo.Text & _
""" /E /B /XJ /XF ""~*.*"" ""*~.*"" ""desktop.ini"" ""Thumbs.db"" "".lock"" "".Sync*""" & _
" /xd ""Rubbish"" "".Sync*"" "".Box Sync"" ""_private"" ""Outlook Files"" /FFT /R:2 /W:5 /V /TEE"
It all works fine except when a user wants to modify a file that is in the middle of being copied. The user gets an error from their program and then has to wait several minutes while the file is being copied (the file can be upto 1GB in size and is being robocopied to a USB stick.
Is there a switch or some way to get Robocopy to not lock the file while it is being copied? obviously Robocopy would need to abort the copy and wait until the file was available so it could try again. I've searched online for a solution but all the problems seem to be the other way round where Robocopy is not copying locked files.
Some more details regarding what I'm doing:
My code calls Robocopy every 30 seconds with above flags (I know robocopy can loop by itself but It wasn't doing quite what I wanted). I envisaged my app just being run at the start of the day and then shutdown at the end of the day. On a different machine a user will open some 3rd party Imaging viewing software which will lock the file being opened, update some of the image's meta data and then save the changes. The problem occurs is when my software locks the image file before the user and then the user can't edit their file.
Thanks
Kristian
Upvotes: 0
Views: 5401
Reputation: 4439
In the code where the user wants to access the file, you could add this before the code to access the file.
If Not p.HasExited Then
p.Close()
End If
Threading.Thread.Sleep(100) ' to give the process time to close the file and close itself
Upvotes: 1