如果路径是可创建文件,如何检查boost :: filesystem?

时间:2017-02-09 02:56:59

标签: c++ boost boost-filesystem

我想检查用户提供的item.toLowerCase().indexOf(item.toLowerCase()) 实际上是否是可创建的文件。可创建意味着:文件名前面的目录存在。

boost::filesystem::path

std::string input = ~/some/dir/file.xyz boost::filesystem::path path(input); if (~/some/dir is a directory) // <-- How to get this? return true; 的解决方案是什么?或者也许有更好的工具?

1 个答案:

答案 0 :(得分:3)

首先,已将filesystem添加到标准中。所以,是的,你应该使用它。在之前,我仍然会使用experimental/filesystem

之类的内容

定义filesystem::path path后,您可以使用parent_path

  

path返回到父目录

您可以在filesystem::exists中使用此path

  

检查给定文件状态或path是否对应于现有文件或目录

因此,if语句中的条件应如下所示:

filesystem::exists(path.parent_path())