std::filesystem::directory_entry::replace_filename
來自 cppreference.com
< cpp | filesystem | directory_entry
void replace_filename( const std::filesystem::path& p ); |
(1) | (C++17 起) |
void replace_filename( const std::filesystem::path& p, std::error_code& ec ); |
(2) | (C++17 起) |
修改目錄項的檔名。
透過 path.replace_filename(p) 有效地修改路徑成員,並呼叫 refresh 以更新快取屬性。如果發生錯誤,快取屬性的值將是不確定的。
此函式不會對檔案系統提交任何更改。
目錄 |
[編輯] 引數
p | - | 要附加到當前儲存路徑的父路徑的路徑 |
ec | - | 非丟擲過載中用於錯誤報告的出參 |
[編輯] 返回值
(無)
[編輯] 異常
任何未標記為 noexcept
的過載都可能在記憶體分配失敗時丟擲 std::bad_alloc。
[編輯] 示例
執行此程式碼
#include <filesystem> #include <iostream> int main() { namespace fs = std::filesystem; { fs::directory_entry entry{"alpha"}; std::cout << entry << '\n'; entry.replace_filename("omega"); std::cout << entry << '\n'; } { fs::directory_entry entry{"/alpha/"}; std::cout << entry << '\n'; entry.replace_filename("omega"); std::cout << entry << '\n'; } }
輸出
"alpha" "omega" "/alpha/" "/alpha/omega"
[編輯] 參閱
賦值內容 (公共成員函式) | |
用另一個路徑替換最後一個路徑元件 ( std::filesystem::path 的公共成員函式) |