在指定目錄下創建文件夾

在博客裏,有人問我這個問題:如何在指定目錄下創建文件夾。這個我還真的沒有做過。用CreateFile,似乎裏面也沒有跟文件夾相關的任何東西。於是就在SDK中搜了一下,CreateDirectory。不錯,這個就可以用來創建文件夾。

下面來仔細學習一下這個API

CreateDirectory

功能

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.

(創建一個新的文件夾。如果基本的文件系統在文件或文件夾上支持安全描述,那麼該函數將在新建的文件夾上應用指定的安全描述)

原型:

BOOL CreateDirectory( 
 LPCTSTR lpPathName,  
  LPSECURITY_ATTRIBUTES lpSecurityAttributes  
); 

參數:

lpPathName:包含將被創建的文件夾路徑的字符串,字符串的長度不超過MAX_PATH 
lpSecurityAttributes:忽略,設爲NULL 

返回值:

成功則返回非零,失敗則返回零。 

備註:

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.

一些文件系統,像NTFS文件系統,對於個別的文件或目錄支持壓縮或加密。以卷格式化的文件系統,一個新的目錄將繼承它父目錄的壓縮和加密特性。 

以上轉載至perfect;
 
實際應用,在C盤目錄下建立一個MRAS的文件
TCHAR lpDest[MAX_PATH] = L"C:\\MARS\\";
     CreateDirectory(lpDest,NULL);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章