Re: reading a opened file



On Tue, 27 Sep 2005 14:38:08 +0200, "snide" <nospam@work> wrote:

>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;

If FileOpen( FileName, fmOpenRead Or fmShareDenyWrite ) <= 0 Then
ShowMessage( SysErrorMessage( GetLastError );

However this may still screw up the other Application if it tries to
write to the file.

.



Relevant Pages