Victor Ruiz
Victor Ruiz

Reputation: 61

Create Directory Permissions

I would like to know something about directory creation in C.

I know in unix based systems, you can create a directory with this function:

mkdir (const char* directory_name,mode_t mode);

but, in windows, mkdir function, only accept one argument, the name of the directory. you cannot specify mode bits for access permissions.

in windows the function for creating the directory is:

_mkdir (const char* directory_name);

so, a portable way to creating a directory is like:

#ifdef WIN32
      _mkdir (directory_name);
#else
       mkdir (directory_name,mode);
#endif

my question is, is there a way to specify permissions like mkdir in unix, but in windows?

Upvotes: 0

Views: 1086

Answers (3)

alk
alk

Reputation: 70911

On windows there also is the chmod() analogon _chmod(): http://msdn.microsoft.com/en-us/library/1z319a54%28v=vs.100%29.aspx

Upvotes: 0

user7116
user7116

Reputation: 64068

You can use CreateDirectory and supply the appropriate SECURITY_ATTRIBUTES (the linked example uses the security descriptor and attributes for a registry key, but fundamentally this is no different than for a file).

Upvotes: 2

md5
md5

Reputation: 23699

You can set permissions with CreateDirectory, from the API Windows.

Upvotes: 0

Related Questions