在vc中创建目录(文件夹)

最简单的方法是执行dos命令:system("md ...")但是这种方法会弹出来dos窗口。 另一种创建目录的方法:

MakeSureDirectoryPathExists

 

The MakeSureDirectoryPathExists function creates all the directories in the specified DirPath, beginning with the root.

 

				BOOL
MakeSureDirectoryPathExists(
PCSTR

DirPath





);

Parameters

DirPath
[in] Pointer to a null-terminated string that specifies a valid path name. If the final component of the path is a directory, not a file name, the string must end with a backslash (\) character.

Return Values

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. To retrieve extended error information, call GetLastError.

Remarks

Each directory specified is created, if it does not already exist. If only some of the directories are created, the function will return FALSE.

All DbgHelp functions, such as this one, are single threaded. Therefore, calls from more than one thread to this function will likely result in unexpected behavior or memory corruption. To avoid this, you must synchronize all concurrent calls from more than one thread to this function.

Requirements

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires DbgHelp.dll on Windows NT 4.0 and Windows Me/98/95.
Header: Declared in Dbghelp.h.
Library: Use Dbghelp.lib.

函数功能描述:该函数创建一个从根目录开始的完整的指定路径.

.函数原型:
 BOOL MakeSureDirectoryPathExists(PCSTR DirPath);

.参数:
 DirPath [in] : 指向一个以NULL结尾的包含正确的指定的路径名,如果路径名的结尾部分不是文件名而是文件夹,那么要以'\'为结束符.

.返回值:
 函数成功返回TRUE;
 函数失败返回FALSE;要获得具体错误信息用GetLastError();

.备注:
 每一级目录如果不存在就创建它,如果只有一些目录被创建了,那么函数返回FALSE.

.示例代码段:
 在用MakeSureDirectoryPathExists前,要在Project->Settings...->Link->/Object/library modules中加入imagehlp.lib.
 {
 BOOL bRet=MakeSureDirectoryPathExists("f:\\Directory1\\Directory2\\Directory3\\");
 //创建目录,要注意结尾"\\".
 ASSERT(bRet);
 bRet=MakeSureDirectoryPathExists("f:\\Directory1\\Directory2\\Directory3");
 //创建目录,但不创建Directory3,因为没有'\\'结尾.
 ASSERT(bRet);
 bRet=MakeSureDirectoryPathExists("f:\\Directory1\\Directory2\\Directory3\\test.txt");
 //创建目录,但不创建文件,可以不用'\\'结尾.
 ASSERT(bRet);
 }

.使用条件:
 Windows NT/2000: 要求是Windows NT 3.1或后续版本。
 Windows 95/98: 要求是 Windows 95或后续版本。
 头文件: 在Dbghelp.h中定义.
 静态库: Dbghelp.lib.

posted on 2007-07-04 23:38 ffan 阅读(11317) 评论(1)  编辑 收藏 引用 所属分类: C/C++/VC

评论

# re: 在vc中创建目录(文件夹) [未登录] 2009-09-30 10:48 ZHANGZHENG

SHOUJIGEQU  回复  更多评论   

只有注册用户登录后才能发表评论。
<2005年8月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

导航

统计

常用链接

留言簿(12)

随笔分类

随笔档案

相册

搜索

最新评论

阅读排行榜

评论排行榜