user105127
user105127

Reputation: 25

How to create a hidden directory

CreateDirectory("C:\\dir",NULL);

I can create a directory by the above method but how can I a create a hidden directory?

I tried something like shell execute function to execute the cmd prompt and made my folder hidden but I know that is not the way.

Thank you

Upvotes: 1

Views: 6041

Answers (3)

jpo38
jpo38

Reputation: 21514

You'll have to set the "hidden" attribute to the folder after you created it.

Use SetFileAttributes function to specify the FILE_ATTRIBUTE_HIDDEN attribute.

According to the documentation, this should work (but I did not test....):

CreateDirectory("C:\\dir",NULL);
SetFileAttributes("C:\\dir",FILE_ATTRIBUTE_HIDDEN);

Upvotes: 6

LePatay
LePatay

Reputation: 322

@jpo38's solution didn't work for me, I had to use "SetFileAttributes" (with an ending "s").

Btw, if your directory is a std::string, use SetFileAttributesA:

SetFileAttributesA(myPath.c_str(), FILE_ATTRIBUTE_HIDDEN)

Upvotes: 1

Humam Helfawi
Humam Helfawi

Reputation: 20264

The command port of hiding a folder or a file is:

attrib +h file_name

So you can create your folder or file then execute this command on it.

Upvotes: 1

Related Questions