How to create hardlink of a file using Python?

PythonServer Side ProgrammingProgramming

The method os.link(src, dst) creates a hard link pointing to src named dst. This method is very useful to create a copy of existing file.

Example

For example, if you have a file called photo.jpg and want to create a  hard link to it called my_photo.jpg, then you could simply use:

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

 Now if you list the files in that directory, you'll get the my_photo

raja
Published on 26-Dec-2017 09:59:03
Advertisements