Python Forum
"os.symlink(targetdir,destfile)" VS "ln -s targetdir destfile" (not equivalent?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"os.symlink(targetdir,destfile)" VS "ln -s targetdir destfile" (not equivalent?
#1
Ok so I been working with Linux for a few years now and I have finally decided to put file and folder linking into practice, considering I need files in multiple locations but i don't want to have dupes... So I'm writing a script to create links to files and folders as needed (where needed)

however I've run into a little discrepancy when running my completed script as opposed to manually creating symlinks

I have a folder 'sourcedir' located at the root of a drive and a folder "foo/bar/targetfolder" (relative to root of drive) which needs a link to the sourcedir folder inside it.

first i get the relative path
relativepath = os.path.relpath('/sourcedir','/foo/bar/targetdir')
which sets relatiivepath to '../../sourcedir'

next i create the link

os.symlink(relativepath,'/foo/bar/targetdir/targetlink)')
if I go to my filemanager and delete the created 'targetlink' it starts deleting all the files in the linked folder

however if I create the link in a terminal with
Quote:ln -s relativepath /foo/bar/targetdir/targetlink'
the profuced symlink shows in my filemanager with a shortcut arrow on it and deleting it simply deletes the link and nothing else. This is the behaviour I'm aiming for and I can't figure out how to get python to do that for me.

I'd appreciate any help
Reply
#2
Unfortunately the issue is not reproducible. I don't think os.symlink() gives a different result from ln -s. Can you check this again?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  equivalent commands saeed_balk 2 2,680 Sep-23-2018, 05:44 AM
Last Post: saeed_balk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020