簡介
C++
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 remote application interface (RAPI) version of this function exists, and it is named CeCreateDirectory.
BOOLCreateDirectory(LPCTSTRlpPathName, LPSECURITY_ATTRIBUTESlpSecurityAttributes);
ParameterslpPathName [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. Return ValuesNonzero indicates success. Zero indicates failure. To get extended error information, call
GetLastError.
RemarksSome file systems, such as NTFS, 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.
第一個參數值為資料夾名稱,第二個參數值為安全屬性,一般設定為NULL即可。如果正確創建,返回值為1,如果沒有正常創建資料夾,則返回0。
特別的:該函式每次調用時都只能創建一級資料夾,即資料夾中不能再包含子資料夾。
當希望創建含有子資料夾的資料夾時,可以先使用該函式創建一級資料夾,然後再使用該函式在一級資料夾下創建子資料夾。如:
希望創建:d:\\TEST\\temp,
則:CString str = “d:\\TEST”;
CreateDirectory(str, NULL);
str = str + “\\temp”;
CreateDirectory(str, NULL);
VB聲明
Declare Function CreateDirectory& Lib "kernel32" Alias "CreateDirectoryA" (ByVal lpNewDirectory As String, lpSecurityAttributes As SECURITY_ATTRIBUTES)
Declare Function CreateDirectoryEx& Lib "kernel32" Alias "CreateDirectoryExA" (ByVal lpTemplateDirectory As String, ByVal lpNewDirectory As String, lpSecurityAttributes As SECURITY_ATTRIBUTES)
說明
創建一個新目錄
返回值
Long,非零表示成功,零表示失敗。會設定GetLastError
參數表
參數 類型及說明
lpTemplateDirectory String,指定一個模板目錄的名字,從中複製默認屬性(比如目錄中檔案的默認壓縮方式)。如設為vbNullString,則表示不使用模板
lpNewDirectory String,新目錄的名字
lpSecurityAttributes SECURITY_ATTRIBUTES,這個結構定義了目錄的安全特性——如果作業系統支持的話
Windows API
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).
BOOL CreateDirectory(
LPCTSTR lpPathName,
LPSECURITY_ATTRIBUTES lpSecurityAttributes
);
Parameters
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.
Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
Remarks
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.
Requirements
OS Versions: Windows CE 1.0 and later.
Header: Winbase.h.
Link Library: Coredll.lib.
See Also
程式例
#include<windows.h>int main(){ CreateDirectory("NewFile",0);//在當前目錄新建一個資料夾 return0;}