Jump to content
Henry Olive

Get, Set FileAtrributes

Recommended Posts

Good Day

I want to make a FOLDER  Hidden then turn to Normal

but i get an error (error point below)

What am i doing wrong ?

Thank You

 

procedure TFolderss.btnHiddenClick(Sender: TObject);
 var
   FileName : String;
   attributes: TFileAttributes;
begin
  FileName := FoldersFOLDERPATH.AsString;

  attributes:= TFile.GetAttributes(FileName);
  Include(attributes,TFileAttribute.faHidden);   Here i get  [dcc64 Error] UFolders.pas(103): E2003 Undeclared identifier: 'attributes '
  TFile.SetAttributes(FileName, attributes);
end;

 

procedure TFolderss.btnNormalClick(Sender: TObject);
 var
   FileName : String;
   attributes: TFileAttributes;
begin
  FileName := FoldersFOLDERPATH.AsString;

  attributes:= TFile.GetAttributes(FileName);
  Exclude(attributes,TFileAttribute.faNormal);
  TFile.SetAttributes(FileName, attributes);
end;;

 

 

Share this post


Link to post

You have some hidden unicode character there. It can happen if you copy paste from the internet.

 

var
   FileName : String;
   attributes: TFileAttributes;
begin
  FileName := 'Test';

  attributes:= TFile.GetAttributes(FileName);

  Include(attributes, TFileAttribute.faHidden);
  TFile.SetAttributes(FileName, attributes);
end;

This compiles.

Share this post


Link to post

This time i get below error msg

FileName :='C:\TEST PROG  -> This is FOLDER not FILE

attributes:= TFile.GetAttributes(FileName); // Error Msg = The specified file was not found

Could be there is still any hidden unicode character ?

( My Form FileFormat shows ANSI )

Thank You

Share this post


Link to post

No, a file is a file a folder is a folder two different things. In case of a folder you should use the TPath (record).

 

attributes:=TPath.GetAttributes(PathName)

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×