How to create softlink of a file using Python?

The method os.symlink(src, dst) creates a symbolic link dst pointing to src. For example, if you have a file called photo.jpg and want to create a softlink/symbolic link to it called my_photo.jpg, then you could simply use:


>>> import os
>>> os.symlink('photo.jpg', 'my_photo.jpg')

Now if you list the files in that directory, you'll get the my_photo.jpg there as well.

Updated on: 13-Dec-2019


Kickstart Your Career

Get certified by completing the course

Get Started