0

I am looking to hide the folder from the explorer. It should not be visible when someone unchecks the show hidden file in folder option.

Is there any Shell API to achieve this, or how do I achieve in MFC or win api or C++, etc? Any ideas and suggestions?

Miklos Aubert
  • 4,405
  • 2
  • 24
  • 33

2 Answers2

0

Use SetFileAttributes with the flag FILE_ATTRIBUTE_HIDDEN. To ensure you don't accidentally clear other attributes you will want to read the directory attributes first using GetFileAttributes.

For example:

void hidePath( const std::wstring& path )
{
    const DWORD attributes = GetFileAttributes( path.c_str() );
    SetFileAttributes( path.c_str(), attributes | FILE_ATTRIBUTE_HIDDEN );
}

Also see: How to hide/un-hide a file without erasing other attributes in C++ on Windows

Community
  • 1
  • 1
Steve
  • 7,171
  • 2
  • 30
  • 52
  • same thing i tried BOOL createFolder12 = CreateDirectory(temp,NULL); SetFileAttributes(temp,FILE_ATTRIBUTE_HIDDEN);this will again visible when the user click the show hidden file and folder in folder option of the windows – sarfaraz Apr 23 '13 at 12:14
  • Your question says that you don't want it to be visible when "Show hidden files" is not checked. Do you mean you don't want it to be visible when it is checked? – Steve Apr 23 '13 at 12:17
0

No, it is not possible using documented nor undocumented Shell API.

Xearinox
  • 3,224
  • 2
  • 24
  • 38