簡體   English   中英

如果路徑是可創建的文件,如何使用 boost::filesystem 檢查?

[英]How to check with boost::filesystem if a path is a creatable file?

我想檢查用戶提供的boost::filesystem::path是否實際上是一個可創建的文件。 Createable 表示:文件名前面的目錄存在。

std::string input = ~/some/dir/file.xyz

boost::filesystem::path path(input);

if (~/some/dir is a directory) // <-- How to get this?
  return true;

boost::filesystem的解決方案是什么? 或者也許有更好的工具?

首先, 在標准中添加了filesystem 所以,是的,你應該使用它。 之前,我仍然會使用類似的東西: experimental/filesystem


一旦定義了filesystem::path path ,就可以使用parent_path

返回父目錄的path

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

檢查給定的文件狀態或path對應於現有文件或目錄

所以你的if語句中的條件應該是這樣的:

filesystem::exists(path.parent_path())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM