View Single Post
  #2  
Old 19-12-2021, 20:42
Razor12911's Avatar
Razor12911 Razor12911 is offline
Noob
 
Join Date: Jul 2012
Location: South Africa
Posts: 3,749
Thanks: 2,170
Thanked 11,206 Times in 2,307 Posts
Razor12911 is on a distinguished road
You need to open the file with the intent to both read and writing to it, if this operation fails then it means the file is in use.

Code:
function IsFileInUse(Filename: String): Boolean;
begin
  Result := False;  
  try
    with TFileStream.Create(Filename,fmOpenReadWrite) do // this should fail
    try
    finally
      Free;
    end;
  except
    Result := True; // this handles the exception and tells you the file is in use
  end;
end;

Last edited by Razor12911; 19-12-2021 at 20:47.
Reply With Quote
The Following User Says Thank You to Razor12911 For This Useful Post:
Cuttlas (21-12-2021)