Namespaces
Variants

std::filesystem:: copy_options

From cppreference.net
헤더 파일에 정의됨 <filesystem>
enum class copy_options {

none = /* unspecified */ ,
skip_existing = /* unspecified */ ,
overwrite_existing = /* unspecified */ ,
update_existing = /* unspecified */ ,
recursive = /* unspecified */ ,
copy_symlinks = /* unspecified */ ,
skip_symlinks = /* unspecified */ ,
directories_only = /* unspecified */ ,
create_symlinks = /* unspecified */ ,
create_hard_links = /* unspecified */

} ;
(C++17부터)

이 타입은 copy() 함수와 copy_file() 함수의 동작을 제어하는 사용 가능한 옵션들을 나타냅니다.

copy_options BitmaskType 요구 사항을 충족합니다 (이는 비트 연산자 operator & , operator | , operator ^ , operator~ , operator & = , operator | = , 그리고 operator ^ = 가 이 타입에 대해 정의됨을 의미합니다). none 은 빈 비트마스크를 나타내며, 다른 모든 열거자는 서로 다른 비트마스크 요소를 나타냅니다.

멤버 상수

다음 옵션 그룹 각각에서 최대 하나의 복사 옵션이 존재할 수 있으며, 그렇지 않을 경우 복사 함수들의 동작은 정의되지 않습니다.

멤버 상수 의미
파일이 이미 존재할 때 copy_file() 동작을 제어하는 옵션
none 오류를 보고함 (기본 동작).
skip_existing 기존 파일을 유지하고 오류를 보고하지 않음.
overwrite_existing 기존 파일을 대체함.
update_existing 기존 파일이 복사되는 파일보다 오래된 경우에만 대체함.
copy() 함수가 하위 디렉터리에 미치는 영향을 제어하는 옵션
none 하위 디렉터리를 건너뜀 (기본 동작).
recursive 하위 디렉터리와 그 내용을 재귀적으로 복사함.
copy() 함수가 심볼릭 링크에 미치는 영향을 제어하는 옵션
none 심볼릭 링크를 따름 (기본 동작).
copy_symlinks 심볼릭 링크가 가리키는 파일 대신 심볼릭 링크 자체를 복사함.
skip_symlinks 심볼릭 링크를 무시함.
copy() 함수의 복사 방식을 제어하는 옵션
none 파일 내용을 복사함 (기본 동작).
directories_only 디렉터리 구조는 복사하지만 비디렉터리 파일은 복사하지 않음.
create_symlinks 파일 사본을 생성하는 대신 원본 파일을 가리키는 심볼릭 링크를 생성함. 참고: 대상 경로가 현재 디렉터리에 있지 않는 한 소스 경로는 절대 경로여야 함.
create_hard_links 파일 사본을 생성하는 대신 원본 파일과 동일한 파일을 가리키는 하드 링크를 생성함.

예제

#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;
int main()
{
    fs::create_directories("sandbox/dir/subdir");
    std::ofstream("sandbox/file1.txt").put('a');
    fs::copy("sandbox/file1.txt", "sandbox/file2.txt"); // 파일 복사
    fs::copy("sandbox/dir", "sandbox/dir2"); // 디렉토리 복사 (비재귀적)
    const auto copyOptions = fs::copy_options::update_existing
                           | fs::copy_options::recursive
                           | fs::copy_options::directories_only
                           ;
    fs::copy("sandbox", "sandbox_copy", copyOptions); 
    static_cast<void>(std::system("tree"));
    fs::remove_all("sandbox");
    fs::remove_all("sandbox_copy");
}

가능한 출력:

.
├── sandbox
│   ├── dir
│   │   └── subdir
│   ├── dir2
│   ├── file1.txt
│   └── file2.txt
└── sandbox_copy
    ├── dir
    │   └── subdir
    └── dir2
8 directories, 2 files

참고 항목

(C++17)
파일 또는 디렉토리 복사
(함수)
(C++17)
파일 내용 복사
(함수)