在指定目录下创建文件夹

在博客里,有人问我这个问题:如何在指定目录下创建文件夹。这个我还真的没有做过。用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);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章