35 Votes

Delphi: Change File Attributes of Files

Info by Progger99 | Last update on 2021-05-12 | Created on 2012-06-19

Sometimes you have to change the file attributes of files via Delphi, for example, to hide a file or to give the file a write-portection. That is how to do it:

procedure TForm1.Button1Click(Sender: TObject);
begin
   FileSetAttr('C:\File.txt', faHidden);
end;

This sets the file to "faHidden", meaning the file will be hidden. Apart from that, the following attributes of the file can be set:

AttributeCodeMeaning
faHidden$00000002Hidden File
faReadOnly$00000001Write Protected File
faSysFile$00000004System File
faArchive$00000020Archive
faDirectory$00000010Folder
faAnyFile$0000003FAny File
faVolumeID$00000008Drive-ID

It is also possible to set several attributes at once. This can be accomplished with:

FileSetAttr('C:\File.txt', faHidden + faReadOnly);

This sets the file "File.txt" to hidden and read-only (write protected).

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

jQuery: Show and hide elements

Tutorial | 0 Comments

VirtualBox: Change Date and Time

Tutorial | 10 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.