Python| os.symlink() 方法
Python中的OS 模块提供了与操作系统交互的功能。操作系统属于 Python 的标准实用程序模块。该模块提供了一种使用操作系统相关功能的可移植方式。
Python中的os.symlink()
方法用于创建符号链接。此方法创建指向名为destination 的源的符号链接。
要阅读有关符号链接/软链接的信息,请参阅本文。
Syntax: os.symlink(src, dst, target_is_directory = False, *, dir_fd = None)
Parameters:
src: A path-like object representing the file system path. This is the source file path for which the symbolic link will be created.
dst: A path-like object representing the file system path. This is the target file path where symbolic link will be created.
target_is_directory (optional): The default value of this parameter is False. If the specified target path is directory then its value should be True.
dir_fd (optional): A file descriptor referring to a directory.
Return type: This method does not return any value.
代码: os.symlink()
方法的使用
# Python program to explain os.symlink() method
# importing os module
import os
# Source file path
src = '/home/ihritik/file.txt'
# Destination file path
dst = '/home/ihritik/Desktop/file(symlink).txt'
# Create a symbolic link
# pointing to src named dst
# using os.symlink() method
os.symlink(src, dst)
print("Symbolic link created successfully")
Symbolic link created successfully
参考: https://docs。 Python.org/3/library/os.html#os.link