Namespaces
Variants

std::experimental::filesystem:: create_symlink, std::experimental::filesystem:: create_directory_symlink

From cppreference.net
헤더 파일에 정의됨 <experimental/filesystem>
void create_symlink ( const path & target, const path & link ) ;
void create_symlink ( const path & target, const path & link, error_code & ec ) ;
(1) (filesystem TS)
void create_directory_symlink ( const path & target, const path & link ) ;
void create_directory_symlink ( const path & target, const path & link, error_code & ec ) ;
(2) (filesystem TS)

심볼릭 링크 link 를 생성하며, 그 대상은 target 으로 설정됩니다. 이는 POSIX symlink() 함수와 동일하게 동작합니다: 경로명 target 이 유효하지 않거나 존재하지 않을 수 있습니다.

일부 운영 체제에서는 심볼릭 링크가 디렉터리를 가리킴을 식별하기 위해 디렉터리 심볼릭 링크 생성을 요구합니다. 이식성이 높은 코드는 POSIX 시스템에서는 구분이 없음에도 불구하고 (1) 대신 (2) 를 사용하여 디렉터리 심볼릭 링크를 생성해야 합니다.

목차

매개변수

target - 심볼릭 링크가 가리킬 경로, 존재하지 않아도 됨
link - 새 심볼릭 링크의 경로
ec - non-throwing 오버로드에서 오류 보고를 위한 출력 매개변수

반환값

(없음)

예외

The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with target as the first argument, link 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
noexcept 명세:
noexcept

참고 사항

일부 운영 체제는 심볼릭 링크를 전혀 지원하지 않거나 일반 파일에 대해서만 지원합니다.

일부 파일 시스템은 운영 체제와 관계없이 심볼릭 링크를 지원하지 않습니다. 예를 들어 일부 메모리 카드와 플래시 드라이브에서 사용되는 FAT 시스템이 그렇습니다.

하드 링크와 마찬가지로, 심볼릭 링크는 파일이 여러 논리적 이름을 가질 수 있도록 합니다. 하드 링크의 존재는 원본 이름이 제거된 후에도 파일의 존재를 보장합니다. 심볼릭 링크는 이러한 보장을 제공하지 않습니다. 사실, 링크가 생성될 때 target 인수로 지정된 파일이 존재하지 않아도 됩니다. 심볼릭 링크는 파일 시스템 경계를 넘을 수 있습니다.

예제

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::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';
    fs::remove_all("sandbox");
}

가능한 출력:

"sandbox/sym1"->"target"
"sandbox/sym2"->"subdir"

참고 항목

파일 속성을 결정합니다
심볼릭 링크 대상을 확인하여 파일 속성을 결정합니다
(함수)
심볼릭 링크의 대상을 얻습니다
(함수)
하드 링크를 생성합니다
(함수)