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.

Advertisements