Forum > General

check if file is in use?

(1/1)

hh:
i only found code for delphi

--- Code: ---function IsFileInUse(FileName: TFileName): Boolean;
var
  HFileRes: HFILE;
begin
  Result := False;
  if not FileExists(FileName) then Exit;
  HFileRes := CreateFile(PChar(FileName),
                         GENERIC_READ or GENERIC_WRITE,
                         0,
                         nil,
                         OPEN_EXISTING,
                         FILE_ATTRIBUTE_NORMAL,
                         0);
  Result := (HFileRes = INVALID_HANDLE_VALUE);
  if not Result then
    CloseHandle(HFileRes);
end;
--- End code ---

eny:
Have a look at FileOpen in SysUtils for the correct Lazarus equivalent for parameter and return types (basically: HFILE is replaced with THandle).

Navigation

[0] Message Index

Go to full version