名前空間
変種
操作

std::experimental::filesystem::copy_options

From cppreference.com
< cpp‎ | experimental‎ | fs
 
 
 
 
ヘッダー <experimental/filesystem> で定義されています
enum class copy_options {

    none = 0,
    skip_existing = 1,
    overwrite_existing = 2,
    update_existing = 4,
    recursive = 8,
    copy_symlinks = 16,
    skip_symlinks = 32,
    directories_only = 64,
    create_symlinks = 128,
    create_hard_links = 256

};
(filesystem TS)

この型は、copy() および copy_file() 関数の動作を制御する利用可能なオプションを表します。

copy_options は、BitmaskType の要件を満たします (これは、ビット演算子 operator&operator|operator^operator~operator&=operator|=、および operator^= がこの型に対して定義されていることを意味します)。

[編集] メンバ定数

以下の各オプショングループにおいて、最大で 1 つのコピーオプションのみを指定できます。それ以外の場合は、コピー関数の動作は未定義となります。

メンバー定数 意味
ファイルが既に存在する場合の copy_file() の動作を制御するオプション
なし 0 エラーを報告します (デフォルトの動作)。
skip_existing 1 エラーを報告せずに、既存のファイルを保持します。
overwrite_existing 2 既存のファイルを上書きします。
update_existing 4 コピー元のファイルよりも古い場合にのみ、既存のファイルを上書きします。
copy() のサブディレクトリに対する効果を制御するオプション
なし 0 サブディレクトリをスキップします (デフォルトの動作)。
recursive 8 サブディレクトリとその内容を再帰的にコピーします。
copy() のシンボリックリンクに対する効果を制御するオプション
なし 0 シンボリックリンクをたどります (デフォルトの動作)。
copy_symlinks 16 シンボリックリンクを、それが指すファイルではなく、シンボリックリンクとしてコピーします。
skip_symlinks 32 シンボリックリンクを無視します。
copy() が行うコピーの種類を制御するオプション
なし 0 ファイルの内容をコピーします (デフォルトの動作)。
directories_only 64 ディレクトリ構造のみをコピーし、ファイルはコピーしません。
create_symlinks 128 ファイルのコピーを作成する代わりに、元のファイルへのシンボリックリンクを作成します。注意: コピー元のパスは絶対パスである必要があります。ただし、コピー先のパスがカレントディレクトリにある場合は除きます。
create_hard_links 256 ファイルのコピーを作成する代わりに、元のファイルと同じファイルを指すハードリンクを作成します。

[編集]

#include <experimental/filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::experimental::filesystem;
 
int main()
{
    fs::create_directories("sandbox/dir/subdir");
    std::ofstream("sandbox/file1.txt").put('a');
    fs::copy("sandbox/file1.txt", "sandbox/file2.txt"); // copy file
    fs::copy("sandbox/dir", "sandbox/dir2"); // copy directory (non-recursive)
    // sandbox holds 2 files and 2 directories, one of which has a subdirectory
    // sandbox/file1.txt
    // sandbox/file2.txt
    // sandbox/dir2
    // sandbox/dir
    //    sandbox/dir/subdir
    fs::copy("sandbox", "sandbox/copy", fs::copy_options::recursive);
    // sandbox/copy holds copies of the above files and subdirectories
    fs::remove_all("sandbox");
}

[編集] 関連項目

ファイルまたはディレクトリをコピーする
(関数) [編集]
ファイルの内容をコピーする
(関数) [編集]
English 日本語 中文(简体) 中文(繁體)