<span style="font-size: 16px;"><strong>BOOL CreateDirectory( LPCTSTR</strong> <em><a target=_blank class="synParam" href="http://blog.youkuaiyun.com/shen_001/article/details/6823049" style="color: rgb(51, 102, 153); text-decoration: none;">lpPathName</a></em></span><span style="font-size: 16px;"><strong>, LPSECURITY_ATTRIBUTES</strong> <em><a target=_blank class="synParam" href="http://blog.youkuaiyun.com/shen_001/article/details/6823049" style="color: rgb(51, 102, 153); text-decoration: none;">lpSecurityAttributes</a></em></span><strong> <span style="font-size: 16px;">);</span></strong> <span style="color: rgb(255, 102, 102);">这个是大多数用户都知道的,但是这个有缺点,只能是一层一层的创建。。。很是麻烦!!!</span>
下面给大家介绍一个函数:
<span style="font-size: 16px;"><strong>BOOL MakeSureDirectoryPathExists( PCSTR</strong> <em><a target=_blank class="synParam" href="http://blog.youkuaiyun.com/shen_001/article/details/6823049" style="color: rgb(51, 102, 153); text-decoration: none;">DirPath</a></em></span><strong> <span style="font-size: 16px;">);</span></strong> <table class="psdkRequirements "><tbody><tr><th><span style="font-size: 16px;">Client</span></th><td><span style="font-size: 16px;">Requires Windows XP or Windows 2000 Professional.</span></td></tr><tr><th><span style="font-size: 16px;">Server</span></th><td><span style="font-size: 16px;">Requires Windows Server 2003 or Windows 2000 Server.</span></td></tr><tr><th><span style="font-size: 16px;">Redistributable</span></th><td><span style="font-size: 16px;">Requires DbgHelp.dll on Windows NT 4.0 and Windows Me/98/95.</span></td></tr><tr><th><span style="font-size: 16px; color: rgb(255, 0, 0);">Header</span></th><td><p><span style="font-size: 16px; color: rgb(255, 0, 0);">Declared in Dbghelp.h.</span></p></td></tr><tr><th><span style="font-size: 16px; color: rgb(255, 0, 0);">Library</span></th><td><p><span style="font-size: 16px; color: rgb(255, 0, 0);">Link to Dbghelp.lib.</span></p></td></tr><tr><th><span style="font-size: 16px; color: rgb(255, 0, 0);">DLL</span></th><td><span style="font-size: 16px; color: rgb(255, 0, 0);">Requires Dbghelp.dll.</span></td></tr></tbody></table>
这个是MSDN上说的需要 Dbghelp.h 但是这样不管你怎么实验,都是不成功!
把头文件改成如下就可以正确使用了
#include "imagehlp.h"
#pragma comment(lib,"imagehlp.lib")
MakeSureDirectoryPathExists("F:\\DVR\\123\\123\\dfd\\asdf\\a\\adf\\");
1.文件路径完全不存在。
2.文件路径存在一部分。
这些都是完全可以实现!!