Python3 os.symlink() Method

Python3 OS File/Directory Methods


Overview

The os.symlink() method is used to create a symbolic link.

A symbolic link is a special file type that contains a reference to another file or directory and can point to a different location in the file system.

Syntax

symlink()The method syntax is as follows:

os.symlink(src, dst, target_is_directory=False)

Parameters

  • src: Path of the target file or directory for which the symbolic link is to be created.
  • dst: Path and name of the symbolic link.
  • target_is_directory(Optional): A boolean value specifyingsrcwhether it is a directory. If set to True,dstit will be created as a symbolic link pointing to the directory.

Return Value

This method has no return value.

Examples

The following example demonstrates the use of the symlink() method:

Example

#!/usr/bin/python3 import os src = '/usr/bin/python' dst = '/tmp/python' # Create a soft link os.symlink(src, dst) print ("Soft link created successfully.")

Executing the above program produces the following output:

Symbolic link created successfully

Python3 OS File/Directory Methods

Other Extensions