os.link(src, dst)
src -- 這對於硬連結將被建立的原始檔路徑
dest -- 這是硬連結將被建立的目標的檔案路徑
#!/usr/bin/python3 import os, sys # Open a file path = "d:\\python3\\foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT ) # Close opened file os.close( fd ) # Now create another copy of the above file. dst = "d:\\tmp\\foo.txt" os.link( path, dst) print ("Created hard link successfully!!")
Created hard link successfully!!