| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <experimental/filesystem> | ||
void rename(const path& old_p,const path& new_p); void rename(const path& old_p,const path& new_p,std::error_code& ec); | (filesystem TS) | |
Moves or renames the filesystem object identified byold_p tonew_p as if by the POSIXrename:
Rename fails if
Contents |
| old_p | - | path to move or rename |
| new_p | - | target path for the move/rename operation |
| ec | - | out-parameter for error reporting in the non-throwing overload |
(none)
#include <experimental/filesystem>#include <fstream>#include <iostream>namespace fs= std::experimental::filesystem; int main(){ fs::path p= fs::current_path()/"sandbox"; fs::create_directories(p/"from");std::ofstream(p/"from/file1.txt").put('a'); fs::create_directory(p/"to"); // fs::rename(p/"from/file1.txt", p/"to/"); // error: to is a directory fs::rename(p/"from/file1.txt", p/"to/file2.txt");// OK// fs::rename(p/"from", p/"to"); // error: to is not empty fs::rename(p/"from", p/"to/subdir");// OK fs::remove_all(p);}
| renames a file (function)[edit] | |
| removes a file or empty directory removes a file or directory and all its contents, recursively (function)[edit] |