Board index » Visual Studio » check if file is in use

check if file is in use

Visual Studio49
Hi,



I am looking for a (graceful) method to determine if a file is in use

(i.e., checking if i can delete or move it is *not* an option :) I am

already using the WMI to obtain a list of directories that I need to

check for the file (it is the same one for each directory), so perhaps

I could use that? Anyway, all suggestions are appreciated...



tia,

arno


-
 

Re:check if file is in use

"arno" <rNOSPAMnospam@xs4all.nl>wrote in message

: I am looking for a (graceful) method to determine if a file is in use

: (i.e., checking if i can delete or move it is *not* an option :) I am

: already using the WMI to obtain a list of directories that I need to

: check for the file (it is the same one for each directory), so perhaps

: I could use that? Anyway, all suggestions are appreciated...



Have you tried setting:



On Error Resume Next

' process file (delete/move)

if err.number>0 then

' process error

err.clear

end if

On Error Goto 0



--

Roland Hall

/* This information is distributed in the hope that it will be useful, but

without any warranty; without even the implied warranty of merchantability

or fitness for a particular purpose. */

Technet Script Center - www.microsoft.com/technet/scriptcenter/">www.microsoft.com/technet/scriptcenter/

WSH 5.6 Documentation - msdn.microsoft.com/downloads/list/webdev.asp">msdn.microsoft.com/downloads/list/webdev.asp

MSDN Library - msdn.microsoft.com/library/default.asp">msdn.microsoft.com/library/default.asp





-

Re:check if file is in use

Roland, I now do it by trying to open the file as textfile for

appending; if that fails it's in use.



On Error Resume Next

Set oFile = oFSO.OpenTextFile(MyFile, ForAppending, False)

If Err.Number = 70 Then

'Permission denied error

IsFileLocked = True

Else

oFile.Close

IsFileLocked = False

End If

On Error GoTo 0



arno



On Thu, 16 Mar 2006 22:54:03 -0600, "Roland Hall" <nobody@nowhere>

wrote:



Quote
"arno" <rNOSPAMnospam@xs4all.nl>wrote in message

news:f6lj125k5s45dloism4q717bemcd0rtu14@4ax.com...

: I am looking for a (graceful) method to determine if a file is in use

: (i.e., checking if i can delete or move it is *not* an option :) I am

: already using the WMI to obtain a list of directories that I need to

: check for the file (it is the same one for each directory), so perhaps

: I could use that? Anyway, all suggestions are appreciated...



Have you tried setting:



On Error Resume Next

' process file (delete/move)

if err.number>0 then

' process error

err.clear

end if

On Error Goto 0



-