Check the File Attributes on Delphi

Function : FileGetAttr(const FileName:String):Integer

In the Delphi program, to find out file attributes, we can use the function FileGetAttr(const FileName:String):Integer

Example:
Create a Form with an Edit, 1 Button, 1 OpenDialog, and 4 Check Box (as shown), doing double-clicking on the Button component, write the following program listing :

procedure TF_CekAtributFile.Button1Click(Sender: TObject);
var mAtribut:Integer;
begin
 if OpenDialog1.Execute then begin
  Edit1.Text:=OpenDialog1.FileName;
  mAtribut:=FileGetAttr(Edit1.Text);
  if mAtribut > 0 then begin
   if (mAtribut and faReadOnly)>0 then
    CheckBoxRead.Checked:=True
    else CheckBoxRead.Checked:=False;
   if (mAtribut and faHidden)>0 then
    CheckBoxHidden.Checked:=True
    else CheckBoxHidden.Checked:=False;
   if (mAtribut and faArchive)>0 then
    CheckBoxArch.Checked:=True
    else CheckBoxArch.Checked:=False;
   if (mAtribut and faSysFile)>0 then
    CheckBoxSys.Checked:=True
    else CheckBoxSys.Checked:=False;
  end else begin
   CheckBoxRead.Checked:=False;
   CheckBoxHidden.Checked:=False;
   CheckBoxArch.Checked:=False;
   CheckBoxSys.Checked:=False;
  end;
 end;
end;

No comments:

Post a Comment