在vc中创建目录(文件夹)
2010-01-16 10:46
806 查看
最简单的方法是执行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 阅读(3771) 评论(1) 编辑 收藏 引用 所属分类: C/C++/VC
相关文章推荐
- java中File文件的创建,删除,复制,移动,以及目录文件的删除等等,主要是文件及文件夹的操作
- 创建多层目录的文件夹
- 扫描一个目录下的所有文件,根据这些文件的创建日期生成一个文件夹,然后把这些文件移入这个文件夹下面
- VC中创建文件夹的方法
- vc 创建文件夹
- Python创建目录文件夹
- VC删除文件夹(非空目录)及其中所有文件
- VB中使用API创建深层目录(建立多层文件夹)
- VC 获取系统特殊文件夹的路径如:系统目录,桌面等
- VC小技巧--创建多级目录
- VC中遍历指定目录中的所有文件和文件夹
- vc创建带新建文件夹按钮的保存对话框
- centos系统之修改新创建文件夹目录显示颜色
- vc++创建文件目录
- C++ mkdir 创建多级文件夹目录
- ubuntu没有权限(不能)创建文件夹(目录)
- C# 文件操作 全收录 追加、拷贝、删除、移动文件、创建目录、递归删除文件夹及文件....
- VC 获取系统特殊文件夹的路径如:系统目录,桌面等
- C# 文件操作 全收录 追加、拷贝、删除、移动文件、创建目录、递归删除文件夹及文件
- VC中判断目录,文件是否存在,创建目录的方法