[英]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
的解決方案是什么? 或者也許有更好的工具?
首先, c++17在標准中添加了filesystem
。 所以,是的,你應該使用它。 在c++17之前,我仍然會使用類似的東西: 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.