PathFileExists 和 PathIsDirectory 的返回值一定要强制转换为bool类型,否知会出错。
#include <stdio.h>
#include <windows.h>
#pragma comment(lib,"shlwapi.lib")
#include "shlwapi.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");
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。