-11 Vote

Delphi: Hide Files

Question by Guest | 2012-09-17 at 21:00

I need a Delphi code to hide a file. Is that possible with Delphi?

It would be helpful, because otherwise, I have to click on each file individually with my mouse to select "hidden". So, hiding would be really easier by using Delphi.

3Best Answer3 Votes

That is possible with Delphi.

Just try out the following code:

FileSetAttr('C:\dat.txt', faHidden);

With this, you hide the file "dat.txt".

Alternatively you can also take the following code to hide the file:

fname := 'C:\dat.txt';  //fname is a string variable

if (FileGetAttr(fname) and faHidden) > 0 then
  FileSetAttr(fname, FileGetAttr(fname) xor faHidden);

And the following to undo the invisibility again:

FileSetAttr(fname, FileGetAttr(fname) or faHidden);

If you are using the two last codes, any other file attributes (such as read-only) will be kept. The first method, however, overwrites any other former attributes of the file.
2012-09-17 at 22:37

ReplyPositive Negative
13 Votes

Here is another of my articles on the same subject:

Change file attributes of files in Delphi

In this tip, I explain all types of file attributes, which can be changed with the help of Delphi.
2012-09-19 at 19:11

ReplyPositive Negative

Related Topics

jQuery: Show and hide elements

Tutorial | 0 Comments

Hide HTML Source Code

Question | 1 Answer

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.


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