How to hide file programmatically?

18 08 2008

Hidden files are very basic and primitive mode of protection. If your file is set as hidden, it won’t get listed to normal user, unless he explicitly enabled – “Show hidden files”. Well, how to make a file really hidden?

You can use the api – SetFileAttributes(). Pass FILE_ATTRIBUTE_HIDDEN as attribute and you’re file will be hidden. Have a look at the code snippet.

// The file, which is to be hidden.
CString csFile = _T("C:\\Autumn Leaves.jpg");

// Hide the file.
SetFileAttributes( csFile, FILE_ATTRIBUTE_HIDDEN );

Another alternative is to use CFile::SetStatus(). Have a look at it too…

Targeted Audience – Beginners.



3 responses

9 09 2008

Nice post, Write some more interesting articles.


9 09 2008

Thanks a lot, buddy!!! Sure, expect more interesting tips. Keep watching!!! 😀


17 06 2009

Hey man! Thanks for the tip!
I have a question though, if I place such a hidden file in the startup folder, it wont start, or will it?

is there a way to make it start, programatically?

I would appreciate and answer, and thanks for the great blog!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: