Re: reading a opened file



I finally came up with this function :


function IsFileInUse(fName : string) : boolean;
var
HFileRes : HFILE;
begin
Result := false;
if not FileExists(fName) then exit;

HFileRes :=CreateFile(pchar(fName),
GENERIC_READ, // or GENERIC_WRITE // desiredaccess
0, // sharemode
nil, // SecurityAttributes
OPEN_EXISTING, // CreationDisposition
FILE_ATTRIBUTE_NORMAL, // FlagsAndAttributes
0); // TemplateFile

Result := (HFileRes = INVALID_HANDLE_VALUE) ;
if not Result then CloseHandle(HFileRes);
end;


Denis


.



Relevant Pages