Re: Sharing violation when trying to delete a file.




"Dave Baker" <newsgroup_poster@xxxxxxxxxx> wrote in message
news:ucdvk1l31regln0a6bmepukp5439ptbp9n@xxxxxxxxxx
>I have a VB5 application (ftpclien.exe) which creates a flag file
> (ftpclien_online.txt) when it is running, and then deletes that flag file
> when it is finished.
>
> I then have another VB5 program (mvmctrl.exe) which looks for that flag
> file
> with the following code:
>
> If Dir(DirToDo + "FTPClien_ONLINE.TXT") <> "" Then
> LogDebug "Didn't do CreateArray - FTPClien_ONLINE.TXT exists", "High"
> BadFTPClient = BadFTPClient + 1 ' increment counter - may have a
> problem!
> Exit Sub
> Else
> BadFTPClient = 0 ' reset it.
> txtStatus.BackColor = vbWhite
> End If
>
> As you can see, it doesn't even open the flag file - just tests whether it
> exists or not.If it exists, mvmctrl.exe does nothing for this cycle and
> waits
> 30 seconds for the next cycle.


Instead of using the Dir function to check existance, use something like
below (air code). It's possible that Dir is putting some kind of lock on
the file. Besides that, using Dir to check for a file's existance can cause
problems with other uses of Dir.

Public Function FileExists(ByVal FileName As String) As Boolean

On Error GoTo EH

If (GetAttr(FileName) And vbDirectory) <> vbDirectory Then
FileExists = True
End If

Exit Function

EH:

FileExists = False

End Function


Oh.....and NEVER use + for string concatenation. Use the & operator.

--
Mike
Microsoft MVP Visual Basic


.