首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::filesystem::create_directory_symlink

Defined in header <filesystem>

?

?

void create_symlink( const std::filesystem::path& target, const std::filesystem::path& link ); void create_symlink( const std::filesystem::path& target, const std::filesystem::path& link, std::error_code& ec );

(1)

(since C++17)

void create_directory_symlink( const std::filesystem::path& target, const std::filesystem::path& link ); void create_directory_symlink( const std::filesystem::path& target, const std::filesystem::path& link, std::error_code& ec );

(2)

(since C++17)

创建符号链接link它的目标设置为target好像是由POSIX符号链接%28%29*路径名称target可能无效或不存在。

有些操作系统需要创建符号链接来标识链接是指向目录的。可移植代码应该使用%282%29来创建目录符号链接,而不是%281%29,即使在POSIX系统上没有区别。

参数

target

-

path to point the symlink to, does not have to exisdt

link

-

path of the new symbolic link

ec

-

out-parameter for error reporting in the non-throwing overload

返回值

%280%29

例外

不占用std::error_code&参数抛文件系统[医]误差关于基础OS API错误,使用target作为第一个论点,link作为第二个参数,操作系统错误代码作为错误代码参数。std::bad_alloc如果内存分配失败,则可能引发。过载std::error_code&参数,如果OSAPI调用失败,则将其设置为OSAPI错误代码,并执行ec.clear()如果没有错误发生。这个过载

noexcept规格:

noexcept

注记

有些操作系统根本不支持符号链接,也不支持常规文件。

有些文件系统不支持符号链接,而不管操作系统如何,例如在某些存储卡和闪存驱动器上使用的FAT系统。

与硬链接一样,符号链接允许文件具有多个逻辑名称。硬链接的存在保证了文件的存在,即使在删除了原始名称之后也是如此。符号链接没有提供这样的保证;实际上,由target参数在创建链接时不存在。符号链接可以跨越文件系统边界。

二次

代码语言:javascript
复制
#include <iostream>
#include <filesystem>
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';
 
    fs::remove_all("sandbox");
}

二次

可能的产出:

二次

代码语言:javascript
复制
"sandbox/sym1"->"target"
"sandbox/sym2"->"subdir"

二次

另见

statussymlink_status (C++17)(C++17)

determines file attributesdetermines file attributes, checking the symlink target (function)

read_symlink (C++17)

obtains the target of a symbolic link (function)

create_hard_link (C++17)

creates a hard link (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com