Identification if the JPG file is open
I am trying to set up an error trap that will detect that the file is already open. This is not a problem when the file is a text file using the following code:
Private Function FILEOPEN (ByVal sFile As String) As Boolean
Dim THISFILEOPEN As Boolean = False
Try
Using f As New IO.FileStream(sFile, IO.FileMode.Open)
THISFILEOPEN = False
End Using
Catch
THISFILEOPEN = True
End Try
Return THISFILEOPEN
End Function
My problem is when the file is an open JPG file and not a text file, does the above function return False indicating that it is not open? I've tried various options for the function, but still can't find a function that can detect if a JPG file is open.
+3
Gordon macdonald
source
to share
1 answer
You shouldn't be doing this behavior. The simple answer is that after checking, but before doing anything with it, the file may become inaccessible. The correct way is to handle the file access exception. You may find this answer helpful:
- fooobar.com/questions/778263 / ...
+4
Neolisk
source
to share