Hello,
Can any one tell me how do I find if a file is in use?
Thanks.
Printable View
Hello,
Can any one tell me how do I find if a file is in use?
Thanks.
EnumWindows might help you if you wish to find a seperate process thats running.
enumprocess api
Nope 'enumprocess' would not help.
The reason being 'enumprocess' would allow me to enumerate the currently running process list. But, how do I know which of the documents is being accessed by them.
Isn't there any API do check if any file is in use?
:confused:
Thanks.
This out. It should help ;)
I am working on a compression program, where I would like to make sure that none of the files that I want to compress are in use.
But, is this the best possible option.
As there may be over a thousand files that I need to compress.
If I have to check each file by opening in a binary mode, wouldn't it make it slow??
:D :D :D
Well it opens the file but it doesn't input it so it shouldn't be TOO slow. But I don't know any other way so I guess you'll have to settle for this, eh? ;)
I found this in API-Guide
VB Code:
'Determine whether a file is already open or not Private Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long Private Declare Function lClose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long Private Function IsFileAlreadyOpen(FileName As String) As Boolean Dim hFile As Long Dim lastErr As Long ' Initialize file handle and error variable. hFile = -1 lastErr = 0 ' Open for for read and exclusive sharing. hFile = lOpen(FileName, &H10) ' If we couldn't open the file, get the last error. If hFile = -1 Then lastErr = Err.LastDllError Else ' Make sure we close the file on success. lClose (hFile) End If ' Check for sharing violation error. sFileAlreadyOpen = (hFile = -1) And (lastErr = 32) End Function Private Sub Form_Load() 'example by Matthew Gates ([email protected]) MsgBox IsFileAlreadyOpen("c:\autoexec.bat") End Sub
Thanks guys.
:D :D :D