Sunwayking

导航

VC(MFC)判断文件/目录是否存在,创建目录[转]

http://hi.baidu.com/yuguo138/blog/item/351ab86e9fca0dda81cb4ab9.html

BOOL CPubFunc::FileExist(CString FileName)
{
CFileFind fFind;
return fFind.FindFile(FileName);
}

BOOL CPubFunc::DirectoryExist(CString Path)
{
WIN32_FIND_DATA fd;
BOOL ret
= FALSE;
HANDLE hFind
= FindFirstFile(Path, &fd);
if ((hFind != INVALID_HANDLE_VALUE) &&
fd.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY))
{
//目录存在
ret = TRUE;

}
FindClose(hFind);
return ret;
}

BOOL CPubFunc::CreateDirectory(CString path)
{
SECURITY_ATTRIBUTES attrib;
attrib.bInheritHandle
= FALSE;
attrib.lpSecurityDescriptor
= NULL;
attrib.nLength
= sizeof(SECURITY_ATTRIBUTES);

return ::CreateDirectory( path, &attrib);
}

 

posted on 2009-12-27 18:40  Sunwayking  阅读(1762)  评论(0编辑  收藏  举报