Jump to content

Understand if a file is open/in use/in handle ?


Recommended Posts

hello,

made a script that rename a large amount of files,

but want undertand if a file is open/in use/handled by

a process before interact with him ... is possible ?

thank you all,

m.

This is an example by Siao.

;~ by Siao
Global Const $GENERIC_READ  = 0x80000000
Global Const $GENERIC_WRITE = 0x40000000
Global Const $OPEN_EXISTING = 3
Global Const $FILE_ATTRIBUTE_NORMAL = 0x80

$file = "d:\Base\work.dat"
If Not FileExists($file) Then Exit

$hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _
                  "str", $file, _
                  "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _
                  "int", 0, _
                  "ptr", 0, _
                  "int", $OPEN_EXISTING, _
                  "int", $FILE_ATTRIBUTE_NORMAL, _
                  "int", 0)

If $hFile[0] = -1 Then
    MsgBox(48, "Warning", "File is open")
Else
    DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile[0])
EndIf

When the words fail... music speaks.

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...