std::filesystem:: create_symlink, std::filesystem:: create_directory_symlink
|
헤더 파일에 정의됨
<filesystem>
|
||
|
void
create_symlink
(
const
std::
filesystem
::
path
&
target,
const std:: filesystem :: path & link ) ; |
(1) | (C++17부터) |
|
void
create_symlink
(
const
std::
filesystem
::
path
&
target,
const
std::
filesystem
::
path
&
link,
|
(2) | (C++17부터) |
|
void
create_directory_symlink
(
const
std::
filesystem
::
path
&
target,
const std:: filesystem :: path & link ) ; |
(3) | (C++17부터) |
|
void
create_directory_symlink
(
const
std::
filesystem
::
path
&
target,
const
std::
filesystem
::
path
&
link,
|
(4) | (C++17부터) |
심볼릭 링크
link
를 생성하며, 대상은
target
으로 설정됩니다. 이는 POSIX
symlink()
함수와 동일하게 동작합니다: 경로명
target
이 유효하지 않거나 존재하지 않을 수 있습니다.
일부 운영 체제에서는 링크가 디렉터리를 가리킨다는 것을 식별하기 위해 심링크 생성이 필요합니다. 이식 가능한 코드는 POSIX 시스템에서는 구분이 없음에도 불구하고 (1,2) 보다는 (3,4) 를 사용하여 디렉터리 심링크를 생성해야 합니다.
목차 |
매개변수
| target | - | 심볼릭 링크가 가리킬 경로, 존재하지 않아도 됨 |
| link | - | 새 심볼릭 링크의 경로 |
| ec | - | non-throwing 오버로드에서 오류 보고를 위한 출력 매개변수 |
반환값
(없음)
예외
noexcept
로 표시되지 않은 모든 오버로드는 메모리 할당이 실패할 경우
std::bad_alloc
을(를) throw할 수 있습니다.
참고 사항
일부 운영 체제는 심볼릭 링크를 전혀 지원하지 않거나 일반 파일에 대해서만 지원합니다.
일부 파일 시스템은 운영 체제와 관계없이 심볼릭 링크를 지원하지 않습니다. 예를 들어 일부 메모리 카드와 플래시 드라이브에서 사용되는 FAT 시스템이 그렇습니다.
하드 링크와 마찬가지로, 심볼릭 링크는 파일이 여러 논리적 이름을 가질 수 있도록 합니다. 하드 링크의 존재는 원본 이름이 제거된 후에도 파일의 존재를 보장합니다. 심볼릭 링크는 그러한 보장을 제공하지 않습니다; 사실, target 인수로 지정된 파일은 링크가 생성될 때 존재하지 않아도 됩니다. 심볼릭 링크는 파일 시스템 경계를 넘을 수 있습니다.
예제
#include <cassert> #include <filesystem> #include <iostream> namespace fs = std::filesystem; int main() { fs::create_directories("sandbox/subdir"); fs::create_symlink("target", "sandbox/sym1"); fs::create_directory_symlink("subdir", "sandbox/sym2"); for (auto it = fs::directory_iterator("sandbox"); it != fs::directory_iterator(); ++it) if (is_symlink(it->symlink_status())) std::cout << *it << "->" << read_symlink(*it) << '\n'; assert(std::filesystem::equivalent("sandbox/sym2", "sandbox/subdir")); fs::remove_all("sandbox"); }
가능한 출력:
"sandbox/sym1"->"target" "sandbox/sym2"->"subdir"
참고 항목
|
(C++17)
(C++17)
|
파일 속성을 결정함
심볼릭 링크 대상을 확인하며 파일 속성을 결정함 (함수) |
|
(C++17)
|
심볼릭 링크의 대상을 얻음
(함수) |
|
(C++17)
|
하드 링크를 생성함
(함수) |