#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");

}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-16
  • 2021-12-20
  • 2021-10-23
  • 2021-10-05
相关资源
相似解决方案