您的位置:首页 > 其它

MakeSureDirectoryPathExists

2010-12-23 09:09 921 查看

MakeSureDirectoryPathExists
Function

Creates all the directories in the specified path, beginning with the
root.

BOOL WINAPI MakeSureDirectoryPathExists(
__in          PCSTR DirPath
);

Parameters

DirPath

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 Value

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.

This function does not support Unicode strings. To specify a Unicode path,
use the SHCreateDirectoryEx
function.

All DbgHelp functions, such as this one, are single threaded. Therefore,
calls fr

om 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

Redistributable

Requires DbgHelp.dll 5.1 or later.

Header

Declared in Dbghelp.h.

Library

Use Dbghelp.lib.

DLL

Requires Dbghelp.dll.

例子:

]#include "stdafx.h"
#include <Windows.h>
//创建路径使用,MSDN里说的头文件和库应该是有问题的!
#include <imagehlp.h>
#pragma comment(lib,"imagehlp.lib")
int _tmain(int argc, _TCHAR* argv[])
{
//Creates all the directories in the specified path
MakeSureDirectoryPathExists("C://test//aa//a.txt");//成功
MakeSureDirectoryPathExists("C://test//aa//bb//a.txt");//成功
MakeSureDirectoryPathExists("C://test//aa//cc//");//成功
MakeSureDirectoryPathExists(".//test//");//成功
MakeSureDirectoryPathExists("..//test//");//成功
MakeSureDirectoryPathExists("./test2/");//不成功
MakeSureDirectoryPathExists("C:/test2/aa/a.txt");//不成功
MakeSureDirectoryPathExists("C://test2");//不成功
return 0;
}


MSDN里说的头文件和库应该是有问题的!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐