std::experimental::filesystem:: copy_file
|
헤더 파일에 정의됨
<experimental/filesystem>
|
||
|
bool
copy_file
(
const
path
&
from,
const
path
&
to
)
;
bool copy_file ( const path & from, const path & to, error_code & ec ) ; |
(1) | (filesystem TS) |
|
bool
copy_file
(
const
path
&
from,
const
path
&
to, copy_options options
)
;
bool copy_file ( const path & from, const path & to, copy_options options, error_code & ec ) ; |
(2) | (filesystem TS) |
copy_options::none
가
options
로 사용됩니다.
copy_file
와 관련 없는 그룹에서도) 동작은 정의되지 않습니다.
- 대상 파일이 존재하지 않는 경우,
-
- from 이 해결되는 파일의 내용과 속성을 to 가 해결되는 파일로 복사합니다 (심볼릭 링크는 따릅니다).
- 그렇지 않고 대상 파일이 이미 존재하는 경우:
-
- 만약 to 와 from 이 equivalent(from, to) 로 판단되었을 때 동일하다면, 오류를 보고합니다.
- 그렇지 않고, options 에 copy_file 제어 옵션이 하나도 설정되지 않았다면, 오류를 보고합니다.
-
그렇지 않고,
options
에
copy_options::skip_existing이 설정되었다면, 아무 작업도 수행하지 않습니다. -
그렇지 않고,
options
에
copy_options::overwrite_existing이 설정되었다면, from 이 가리키는 파일의 내용과 속성을 to 이 가리키는 파일로 복사합니다. -
그렇지 않고,
options
에
copy_options::update_existing이 설정되었다면, last_write_time() 에 정의된 대로 from 이 to 보다 최신인 경우에만 파일을 복사합니다.
비예외(non-throwing) 오버로드는 오류가 발생할 경우 false 를 반환합니다.
목차 |
매개변수
| from | - | 소스 파일 경로 |
| to | - | 대상 파일 경로 |
| ec | - | non-throwing 오버로드에서 오류 보고를 위한 출력 매개변수 |
반환값
true 파일이 복사된 경우, false 그렇지 않은 경우.
예외
The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with from as the first argument, to as the second argument, and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has참고 사항
이 함수들은 최대 한 번의 직접 또는 간접 호출을 포함하며,
status(to)
(파일 존재 여부 확인과
copy_options::update_existing
옵션의 경우 마지막 수정 시간 확인에 모두 사용됨)를 호출합니다.
디렉터리를 복사할 때
copy_file
를 사용하면 오류가 보고됩니다: 해당 경우에는
copy
를 사용하십시오.
copy_file
는 심볼릭 링크를 따릅니다: 해당 기능을 위해서는
copy_symlink
또는
copy
와
copy_options::copy_symlinks
를 사용하십시오.
예제
#include <experimental/filesystem> #include <fstream> #include <iostream> namespace fs = std::experimental::filesystem; int main() { fs::create_directory("sandbox"); std::ofstream("sandbox/file1.txt").put('a'); fs::copy_file("sandbox/file1.txt", "sandbox/file2.txt"); // 이제 sandbox에 두 개의 파일이 있습니다: std::cout << "file1.txt holds : " << std::ifstream("sandbox/file1.txt").rdbuf() << '\n'; std::cout << "file2.txt holds : " << std::ifstream("sandbox/file2.txt").rdbuf() << '\n'; // 디렉토리 복사 실패 fs::create_directory("sandbox/abc"); try { fs::copy_file("sandbox/abc", "sandbox/def"); } catch (fs::filesystem_error& e) { std::cout << "Could not copy sandbox/abc: " << e.what() << '\n'; } fs::remove_all("sandbox"); }
가능한 출력:
file1.txt holds : a file2.txt holds : a Could not copy sandbox/abc: copy_file: Is a directory: "sandbox/abc", "sandbox/def"
참고 항목
|
복사 작업의 의미론을 지정함
(열거형) |
|
|
심볼릭 링크를 복사함
(함수) |
|
|
파일 또는 디렉토리를 복사함
(함수) |