Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

CreateDirectoryA function (fileapi.h)

  • 2023-06-01
Feedback

In this article

Creates a new directory. If the underlying file system supports security on files anddirectories, the function applies a specified security descriptor to the new directory.

To specify a template directory, use theCreateDirectoryEx function.

To perform thisoperation as a transacted operation, use theCreateDirectoryTransacted function.

Syntax

BOOL CreateDirectoryA(  [in]           LPCSTR                lpPathName,  [in, optional] LPSECURITY_ATTRIBUTES lpSecurityAttributes);

Parameters

[in] lpPathName

The path of the directory to be created.

By default, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, prepend "\\?\" to the path. For more information, seeNaming Files, Paths, and Namespaces.

Tip

Starting with Windows 10, Version 1607, you can opt-in to remove the MAX_PATH limitation without prepending "\\?\". See the "Maximum Path Length Limitation" section ofNaming Files, Paths, and Namespaces for details.

[in, optional] lpSecurityAttributes

A pointer to aSECURITY_ATTRIBUTESstructure. ThelpSecurityDescriptor member of the structure specifies a securitydescriptor for the new directory. IflpSecurityAttributes isNULL, the directory gets a default security descriptor. The ACLs in the defaultsecurity 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 whenGetVolumeInformationreturnsFS_PERSISTENT_ACLS.)

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, callGetLastError. Possible errors include thefollowing.

Return codeDescription
ERROR_ALREADY_EXISTS
The specified directory already exists.
ERROR_PATH_NOT_FOUND
One or more intermediate directories do not exist; this function will only create the final directory in the path.

Remarks

Some file systems, such as the NTFS file system, support compression or encryption for individual files anddirectories. On volumes formatted for such a file system, a new directory inherits the compression and encryptionattributes of its parent directory.

An application can obtain a handle to a directory by callingCreateFile with theFILE_FLAG_BACKUP_SEMANTICS flag set. For a code example, seeCreateFile.

To support inheritance functions that query the security descriptor of this object may heuristically determineand report that inheritance is in effect. SeeAutomatic Propagation of Inheritable ACEsfor more information.

In Windows 8 and Windows Server 2012, this function is supported by the following technologies.

TechnologySupported
Server Message Block (SMB) 3.0 protocolYes
SMB 3.0 Transparent Failover (TFO)Yes
SMB 3.0 with Scale-out File Shares (SO)Yes
Cluster Shared Volume File System (CsvFS)Yes
Resilient File System (ReFS)Yes
 

Examples

For an example, seeRetrieving and Changing File Attributes.

Note

The fileapi.h header defines CreateDirectory as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, seeConventions for Function Prototypes.

Requirements

RequirementValue
Minimum supported clientWindows XP [desktop apps | UWP apps]
Minimum supported serverWindows Server 2003 [desktop apps | UWP apps]
Target PlatformWindows
Headerfileapi.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See also

CreateDirectoryEx

CreateDirectoryTransacted

CreateFile

Creating and Deleting Directories

Directory Management Functions

RemoveDirectory

SECURITY_ATTRIBUTES

SECURITY_INFORMATION


Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo