joshua.thomas.bird
joshua.thomas.bird

Reputation: 695

How to create a hard link from within a Python script on a Mac?

I'm assuming with a call to a UNIX shell, but I was wondering if there are other options from within Python.

Upvotes: 0

Views: 2582

Answers (2)

evading
evading

Reputation: 3090

My guess would also be that it is a permission problem. For me (OS X 10.7.3), this works:

$ ls
slask.py  system.py  system1.gif  system2.gif

$ python
>>> from os import *
>>> link('system2.gif', 'mylink.gif')
>>> exit()

$ ls
mylink.gif  slask.py  system.py  system1.gif  system2.gif

And just to make it clear, "Hard links may not normally refer to directories and may not span file systems."

This is because hard linking a directory could create an infinite loop. So directories need to be created using os.mkdir. Then files can be hard linked into that new directory.

Upvotes: 4

rkhayrov
rkhayrov

Reputation: 10260

os.link claims to work on all Unix platforms. Are there any OS X specific issues with it?

Upvotes: 1

Related Questions