读书人

MFC上。怎么超找一个文件夹

发布时间: 2012-09-08 10:48:07 作者: rapoo

MFC下。如何超找一个文件夹
我只要查找一个文件夹。然后判断有没有这个文件夹。如果没有。。就建立一个temp的名字的文件夹。。。请给代码啊。求代码。。。。

[解决办法]
可以直接使用API函数
BOOL SetCurrentDirectory(
LPCTSTR lpPathName // new directory name
);
设置文件夹为当前目录,如果失败,表示没有这个目录。
然后使用
BOOL CreateDirectory(
LPCTSTR lpPathName, // directory name
LPSECURITY_ATTRIBUTES lpSecurityAttributes // SD
);
创建这个目录就可以了。
#include <windows.h>
#incldue <stdio.h>

if(!SetCurrentDirectoryA("C:\\temp"))
{
if(CreateDirectoryA("C:\\temp", NULL))
{
printf("创建目录成功\n");
}
}


[解决办法]

C/C++ code
#include <windows.h>#include <string>#include "shlwapi.h"#pragma comment(lib,"shlwapi.lib")int main(){        char* path= "D:\\temp ";     if(PathFileExists(path)==FALSE)    {            if(CreateDirectory(path,NULL)==FALSE)             printf("error");    }     return 0;} 

读书人网 >C++

热点推荐