Reputation: 71
I have sometimes a 'file not found' error on the 'DeleteFile' line of this small script: (I guess when several clients open the script as the same time)
if objFSO.FileExists(fileName) then
Set f = objFSO.GetFile(fileName)
if DateDiff("d", f.DateLastModified, date()) > 3 then
Application.Lock
objFSO.DeleteFile(fileName)
Application.Unlock
end if
Set f = nothing
end if
But this should be protected by the 'FileExists' on the first line? Any idea ? Thanks.
Upvotes: 0
Views: 573
Reputation: 19613
You're running into a race condition. The file attributes are cached in the second line with GetFile
. If the file exists at that point, the code will continue to run. You either need to lock before that point, or refresh your attribute cache and double-check existence after Application.Lock
.
Upvotes: 2