Scalabium Software

SMExport/SMImport suites
Knowledge for your independence'.
Home Delphi and C++Builder tips


#66: Is a file in use or not?

In some situations of your applications you must check: the file is locked for exclusive access or not. The next function you can use for this check:

function FileInUse(FileName: string): 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;


Published: February 16, 2000

See also
 
Paradox Password Recovery
Paradox Viewer
dBase Viewer
Protected Storage Viewer
Database Information Manager
DBISAM Password Recovery
Viewer for TNEF-files (winmail.dat)
DBExport tools
SMReport
Fast Document Viewer
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2017, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising