Detect if file is ReadOnly

The following function will return True if a file is read only.

function IsReadOnly(const FileName: string): Boolean;
var
  sr: TSearchRec;
begin
  (* Assume not read only *)
  Result := False;

  if FindFirst(FileName, faAnyFile, sr) = 0 then
  begin
    Result := (sr.Attr and faReadOnly) <> 0;
    FindClose(sr);
  end;
end;

 

Share this article!

Follow us!

Find more helpful articles: