Applies to: desktop apps only
Creates a new directory with the attributes of a specified template directory. If the underlying file system supports security on files and directories, the function applies a specified security descriptor to the new directory. The new directory retains the other attributes of the specified template directory.
To perform this operation as a transacted operation, use the CreateDirectoryTransacted function.
Syntax
BOOL WINAPI CreateDirectoryEx( __in LPCTSTR lpTemplateDirectory, __in LPCTSTR lpNewDirectory, __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes );
Parameters
- lpTemplateDirectory [in]
-
The path of the directory to use as a template when creating the new directory.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.
- lpNewDirectory [in]
-
The path of the directory to be created.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File.
- lpSecurityAttributes [in, optional]
-
A pointer to a SECURITY_ATTRIBUTES structure. The lpSecurityDescriptor member of the structure specifies a security descriptor for the new directory.
If lpSecurityAttributes is NULL, the directory gets a default security descriptor. The access control lists (ACL) in the default security descriptor for a directory are inherited from its parent directory.
The target file system must support security on files and directories for this parameter to have an effect. This is indicated when GetVolumeInformation returns FS_PERSISTENT_ACLS.
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero (0). To get extended error information, call GetLastError. Possible errors include the following.
| Return code | Description |
|---|---|
|
The specified directory already exists. |
|
One or more intermediate directories do not exist. This function only creates the final directory in the path. To create all intermediate directories on the path, use the SHCreateDirectoryEx function. |
Remarks
The CreateDirectoryEx function allows you to create directories that inherit stream information from other directories. This function is useful, for example, when you are using Macintosh directories, which have a resource stream that is needed to properly identify directory contents as an attribute.
Some file systems, such as the NTFS file system, support compression or encryption for individual files and directories. On volumes formatted for such a file system, a new directory inherits the compression and encryption attributes of its parent directory.
You can obtain a handle to a directory by calling the CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag set. For a code example, see CreateFile.
To support inheritance functions that query the security descriptor of this object can heuristically determine and report that inheritance is in effect. For more information, see Automatic Propagation of Inheritable ACEs.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | CreateDirectoryExW (Unicode) and CreateDirectoryExA (ANSI) |
See also
- CreateDirectory
- CreateDirectoryTransacted
- CreateFile
- Creating and Deleting Directories
- Directory Management Functions
- RemoveDirectory
- SECURITY_ATTRIBUTES
Send comments about this topic to Microsoft
Build date: 4/17/2012