複製鏈接
請複製以下鏈接發送給好友

CreateDirectory

鎖定
CreateDirectory是計算機語言,程序含義為第一個參數值為文件夾名稱,第二個參數值為安全屬性,一般設置為NULL即可。如果正確創建,返回值為1,如果沒有正常創建文件夾,則返回0。
中文名
CreateDirectory
説    明
創建一個新目錄
返回值
會設置GetLastError
參數 類型
指定一個目錄名字複製默認屬性

CreateDirectory簡介

CreateDirectory, CreateDirectoryEx

CreateDirectoryC++

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);

CreateDirectoryVB聲明

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)

CreateDirectory説明

創建一個新目錄

CreateDirectory返回值

Long,非零表示成功,零表示失敗。會設置GetLastError

CreateDirectory參數表

參數 類型及説明
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
CeCreateDirectory (RAPI) | CreateFile | RemoveDirectory

CreateDirectory程序例

#include<windows.h>
int main()
{
    CreateDirectory("NewFile",0);//在當前目錄新建一個文件夾
    return0;
}