Python | os.symlink() method
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.symlink() method in Python is used to create symbolic link. This method creates symbolic link pointing to source named destination.
To read about symbolic links/soft links, please refer to this article.
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.
Code: Use of os.symlink() method
# 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
Reference: https://docs.python.org/3/library/os.html#os.link
Recommended Posts:
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.waitid() method
- Python | shutil.which() method
- Python PIL | getpalette() Method
- Python PIL | getcolors() Method
- Python | os.WIFEXITED() method
- Python | Tensorflow cos() method
- Python | os.major() method
- Python | os.stat() method
- Python | os.minor() method
- Python | os.fstat() method
- Python | os.umask() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



