How can I test if a file is locked?

Posted on 2009-04-22
Last Modified: 2012-05-06
Hello guys

Is there any way to know if a file is locked? That is, it is being used?

Question by:hidrau
    LVL 4

    Expert Comment

    You can use an application like OpenedFilesView to check.
    LVL 4

    Accepted Solution

    Sorry just noticed your topic was based on delphi,  have a look here:
    LVL 1

    Author Closing Comment

    Wonderful function
    Thanks very much
    LVL 1

    Author Comment

    This function is from the link

    function IsFileInUse(fName : string) : boolean;
    var HFileRes : HFILE;
      Result := False;
      if not FileExists(fName) then
      HFileRes := CreateFile(pchar(fName),
                             GENERIC_READ or GENERIC_WRITE,
                             0, nil, OPEN_EXISTING,
                             FILE_ATTRIBUTE_NORMAL, 0);
      Result := (HFileRes = INVALID_HANDLE_VALUE);
      if not Result then

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now