Jump to content

How to check: File is in use


Go to solution Solved by Yashied,

Recommended Posts

Posted

for example

if I open a rtf/pdf document

how I can check state of this document (file in use)

this same question to all other files (txt , exe, ......)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

FileGetAttrib ( "filename" )

what's mind

"O" = OFFLINE

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

According to MSDN:

"The data of the file is not immediately available. This attribute indicates that the file data has been physically moved to offline storage. Applications should not arbitrarily change this attribute."

My UDFs and Tutorials:

  Reveal hidden contents

 

  • Solution
Posted (edited)

#Include <WinAPI.au3>

ConsoleWrite(_FileIsUses(@ScriptDir & '\My.pdf') & @CR)

Func _FileIsUses($sFile)

    Local $hFile = _WinAPI_CreateFile($sFile, 2, 2, 0)

    If $hFile Then
        _WinAPI_CloseHandle($hFile)
        Return 0
    EndIf

    Local $Error = _WinAPI_GetLastError()

    Switch $Error
        Case 32 ; ERROR_SHARING_VIOLATION
            Return 1
        Case Else
            Return SetError($Error, 0, 0)
    EndSwitch
EndFunc   ;==>_FileIsUses

Edited by Yashied

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
  • Recently Browsing   0 members

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