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