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