//判断文件夹是否存在不存在创建 int QueryFolder(CString dir) { if (dir[dir.GetLength() - 1] != ‘/’) { dir += ‘/’; } CString strName = dir; CString strDecompose; while (1) { int nRetFind = strName.Find(’/’); if (nRetFind == -1) { break; } strDecompose += strName.Left(nRetFind + 1); strName.Delete(0, nRetFind + 1); if (!PathIsDirectory(strDecompose))//判断路径是否存在 { if (CreateDirectory(strDecompose, NULL) == 0)//新建文件夹 { int aa = GetLastError(); return 1; }; } } return 0;//can not make a dir; }
//判断文件夹是否存在不存在创建 int QueryFolder(const char* dir) { int m = 0, n; std::string str1, str2; str1 = dir; str2 = str1.substr(0, 2); str1 = str1.substr(3, str1.size()); int nErrorRet = 0; while (m >= 0) { m = str1.find(’\’);
str2 += '\\' + str1.substr(0, m);
n = _access(str2.c_str(), 0); //判断该目录是否存在
if (n == -1)
{
nErrorRet = _mkdir(str2.c_str()); //创建目录 返回-1出现错误
}
str1 = str1.substr(m + 1, str1.size());
}
return nErrorRet;//can not make a dir;
}
|