目录是否存在的检查:
BOOL FolderExist(CString strPath)
{
WIN32_FIND_DATA wfd;
BOOL rValue = FALSE;
HANDLE hFind = FindFirstFile(strPath, &wfd);
if ((hFind != INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
rValue = TRUE;
}
FindClose(hFind);
return rValule;
}
文件存在性检查:
BOOL FileExist(CString strFileName)
{
CFileFind fFind;
return fFind.FindFile(strFileName);
}
创建目录:
BOOL CreateFolder(CString strPath)
{
SECURITY_ATTRIBUTES attrib;
attrib.bInheritHandle = FALSE;
attrib.lpSecurityDescriptor = NULL;
attrib.nLength =sizeof(SECURITY_ATTRIBUTES);
//上面定义的属性可以省略。 直接return ::CreateDirectory( path, NULL); 即可
return ::CreateDirectory( strPath, &attrib);
}
本文介绍了如何使用C++检查文件及目录是否存在,以及如何创建新的目录。包括了具体的函数实现方式,如通过`FindFirstFile`检查目录的存在性,用`CFileFind`类检查文件的存在性,并提供了一个创建目录的例子。
1万+

被折叠的 条评论
为什么被折叠?



