Modifying the filesystem
Most of the <filesystem>
header's facilities are concerned with examining the filesystem, not modifying it. But there are several gems hidden in the rubble. Many of these functions seem designed to make the effects of the classic POSIX command-line utilities available in portable C++:
fs::copy_file(old_path, new_path)
: Copy the file atold_path
to a new file (that is, a new inode) atnew_path
, as if bycp -n
. Error ifnew_path
already exists.fs::copy_file(old_path, new_path, fs::copy_options::overwrite_existing)
: Copyold_path
tonew_path
. Overwritenew_path
if possible. Error ifnew_path
exists and is not a regular file, or if it's the same asold_path
.fs::copy_file(old_path, new_path, fs::copy_options::update_existing)
: Copyold_path
tonew_path
. Overwritenew_path
if and only if it's older than the file atold_path
.fs::copy(old_path, new_path, fs::copy_options::recursive | fs::copy_options::copy_symlinks)
: Copy an entire directory fromold_path
tonew_path...