如何检查给定路径是否指向现有文件 OR 目录
how to check if given path is pointing to existing file OR directory?
我需要一个函数,如果给定路径上有一个实体,无论是文件还是目录,它都会简单地返回布尔值。在 winapi 或 stl 中使用什么函数?
GetFileAttributes()
将返回有关文件系统对象的信息,可以查询这些信息以确定它是文件还是目录,如果不存在,它将失败。
例如:
#include <windows.h>
#include <iostream>
int main(int argc, char* argv[])
{
if (2 == argc)
{
const DWORD attributes = GetFileAttributes(argv[1]);
if (INVALID_FILE_ATTRIBUTES != attributes)
{
std::cout << argv[1] << " exists.n";
}
else if (ERROR_FILE_NOT_FOUND == GetLastError())
{
std::cerr << argv[1] << " does not existn";
}
else
{
std::cerr << "Failed to query "
<< argv[1]
<< " : "
<< GetLastError()
<< "n";
}
}
return 0;
}
There is PathFileExists
(shlwapi)
确定文件系统对象(如文件或文件)的路径 文件夹有效。
(UNC 股份的注意事项)
相关文章:
- C++ 读取整个文件目录
- 通过搜索硬盘驱动器查找文件目录
- 在 Apache Velocity 模板语言中获取文件目录
- 将文件目录打印到数据结构中
- 是否可以在编译后创建 CMake 目标和文件目录?
- 带有引号+组合目录 c++ 的 ifstream 文件目录
- 如何在 Windows 上的 c++ 中管理文件/目录的发现和使用
- 如何从Windows中的可执行文件中推断出文件/目录路径
- 为什么我的文件/目录操作在Windows上工作正常,但在Linux上不能
- 使用 depend将对象文件保存在相同的生成文件目录中
- Visual Studio - C++ - 以 32 位或 64 位构建和运行应用程序 - 从适当的程序文件目录加载 D
- 如何启动文件/目录/URL的关联应用程序
- 如果文件/目录大小增加以上,有没有办法在Linux中重新呼叫
- Xcode C++头文件目录
- C++获取程序文件目录,附加额外路径并执行
- gradle实验通过srcDir-srcFile指令包含文件目录
- 带有变量的C++文件/目录stat
- 试图插入用户定义的对象到一个矢量,而我从文件目录读取值
- 从文件目录执行重复的功能,使用OpenCV 3.0
- 如何使用Boost.Filesystem检查两个路径是否指向同一个文件/目录