#include <windows.h> void main() { //文件或文件夹都可以判断,最后的\号有无都没关系 if (-1!=GetFileAttributes("D:\MyProjects\临时程序")) //如果文件夹存在, 最后的\号有无都没关系 printf("文件夹存在 "); if (-1!=GetFileAttributes("D:\MyProjects\临时程序\Desktop.ini")) //如果文件存在 printf("文件存在 "); //可以区分是路径还是文件,PathIsDirectory返回值必须强制转为(bool) if (true==(bool)PathIsDirectory("D:\MyProjects\临时程序")) //最后的\号有无都没关系 printf("测试PathIsDirectory 文件夹存在 "); else printf("测试PathIsDirectory 文件夹不存在 "); //PathFileExists返回值必须强制转为(bool) //文件或文件夹都可以判断,最后的\号有无都没关系 if (true==(bool)PathFileExists("D:\MyProjects\临时程序\")) //最后的\号有无都没关系 printf("PathFileExists 文件夹存在 "); else printf("PathFileExists 文件夹不存在 "); if (true==(bool)PathFileExists("D:\MyfProjects\临时程序\Desktop.ini")) printf("PathFileExists 文件存在 "); else printf("PathFileExists 文件不存在 "); }