使用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.

你可能感兴趣的:(thread,windows,function,String,Path,behavior)