Python os.link() Method
Example
Create a hard link pointing to source file path:
#Import os Library
import os
# Source file path
src = "/home/user/file.txt"
#Create a copy of the file above
# Destination file path
dst = "/home/python/file.txt"
os.link(src, dst)
Definition and Usage
The os.link()
method creates a hard link pointing
to source named destination. It is used to create a copy of existing file.
Note: Available on Windows and Unix platforms.
Syntax
os.link(src, dst, src_dir_fd, dst_dir_fd,
follow_symlinks)
Parameter Values
Parameter | Description |
---|---|
src | Required. The source file path for which hard link would be created |
dst | Required. The destination file path where hard link would be created |
src_dir_fd | Optional. If the specified src path is absolute then the specified src path is relative to the directory associated with src_dir_fd. The default value is None |
dst_dir_fd | Optional. A file descriptor referring to a directory. The default value is None |
follow_symlinks | Optional. A Boolean value. The default value is True |
Technical Details
Return Value: | None |
---|---|
Python Version: | pre -2.6 |
Change Log: | 3.2 - Added Windows support. 3.3 - Added src_dir_fd, dst_dir_fd, and follow_symlinks parameters. 3.6 - Accepts a path-like object for src and dst. |