首页 > 代码库 > CreateDirectory 创建文件夹

CreateDirectory 创建文件夹

函数原型:

CreateDirectory(
  LPCTSTR lpPathName,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes
);

简介:

     CreateDirectory 是Win32API函数,用于创建文件夹。
     参数 lpPathName 表示路径
    参数 lpSecurityAttributes 表示安全属性

============================================================================
例子(程序段):

        //设置属性
        SECURITY_ATTRIBUTES attribute;
        attribute.nLength = sizeof(attribute);
        attribute.lpSecurityDescriptor = NULL;
        attribute.bInheritHandle = FALSE;
        //创建
        if(CreateDirectoryA(“d:\\yanlei”,&attribute) == 0)
            AfxMessageBox("false");

==========================================================================
MSDN上的相关信息:

This function creates a new directory. If the underlying file system supports security on files and directories, the function applies a specified security descriptor to the new directory.

A RAPI version of this function exists, and it is named CeCreateDirectory (RAPI).

CreateDirectory(
  LPCTSTR <>
  LPSECURITY_ATTRIBUTES < EM>
);

lpPathName

[in] Long pointer to a null-terminated string that specifies the path of the directory to be created.

There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the CreateDirectory function parses paths.

lpSecurityAttributes

[in] Ignored; set to NULL.

<>

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

CreateDirectory is not recursive. The function can create only the final directory in a path. That is, if a parent or intermediate directory does not exist, the function will fail with error message ERROR_PATH_NOT_FOUND.

Some file systems, such as 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.

In Windows CE 5.0 and later, full path canonicalization is performed before CreateDirectory processes a path name. As a result, trailing backslashes that may appear in a user-provided path name are ignored.

OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coredll.lib.