System.IOUtilsユニットの関数を使うとファイルの属性を簡単に取得できます。
System.IOUtilsユニットはDelphi 2010以降で使用できます。
使用するユニット
uses System.IOUtils;
ファイルの属性を取得する
ファイルの属性を取得するには、System.IOUtils.TFile.GetAttributesを使用します。
返値のTFileAttributesはTFileAttributeの列挙型です。
procedure TForm1.Button1Click(Sender: TObject);
var
Path: string;
Attr: TFileAttributes;
begin
// 属性を取得したいファイルのパス
Path := 'C:\sample\file.txt';
// ファイルの属性を取得する
Attr := TFile.GetAttributes(Path);
// 読み取り専用ファイル
if TFileAttribute.faReadOnly in Attr then
ShowMessage('読み取り専用ファイル');
// 隠しファイル
if TFileAttribute.faHidden in Attr then
ShowMessage('隠しファイル');
// システムファイル
if TFileAttribute.faSystem in Attr then
ShowMessage('システムファイル');
end;
取得できる属性はTFileAttributeをご覧ください。