16,472
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
void main()
{
//文件或文件夹都可以判断,最后的\\号有无都没关系
if (-1!=GetFileAttributes("D:\\MyProjects\\临时程序")) //如果文件夹存在, 最后的\\号有无都没关系
printf("文件夹存在\n");
if (-1!=GetFileAttributes("D:\\MyProjects\\临时程序\\Desktop.ini")) //如果文件存在
printf("文件存在\n");
//可以区分是路径还是文件,PathIsDirectory返回值必须强制转为(bool)
if (true==(bool)PathIsDirectory("D:\\MyProjects\\临时程序")) //最后的\\号有无都没关系
printf("测试PathIsDirectory 文件夹存在\n");
else
printf("测试PathIsDirectory 文件夹不存在\n");
//PathFileExists返回值必须强制转为(bool)
//文件或文件夹都可以判断,最后的\\号有无都没关系
if (true==(bool)PathFileExists("D:\\MyProjects\\临时程序\\")) //最后的\\号有无都没关系
printf("PathFileExists 文件夹存在\n");
else
printf("PathFileExists 文件夹不存在\n");
if (true==(bool)PathFileExists("D:\\MyfProjects\\临时程序\\Desktop.ini"))
printf("PathFileExists 文件存在\n");
else
printf("PathFileExists 文件不存在\n");
}
CString strPath ="...";
if(_access(strLoadIo,0) != -1)/*路径是否存在*/
{
/*路径存在*/
}
else
{
/*路径不存在*/
}