Python os.symlink() Method



The Python method os.symlink() is used to create a symbolic link in the file system. The symlink is also known as soft link. It serves as a reference or pointer to another file or directory.

Syntax

Following is the syntax for os.symlink() method −

os.symlink(src, dest)

Parameters

The Python os.symlink() method accept two parameters, which are as follows −

  • src − This parameter specifies the path of the source file.

  • dest − It specifies the path where the symbolic link should be created.

Return Value

The Python os.symlink() method does not return any value.

Example

In the following example, we are creating a symbolic link using the symlink() method.

import os

src = "/home/tp/Python/Tutorials/tmpfile"
dst = "/home/tp/Python/tmpdir"

# This creates a symbolic link 
os.symlink(src, dst)
print ("symlink created")

On running the above program, it will create a symbolic link in /tmpdir directory.

symlink created
python_files_io.htm
Advertisements