Greetings all,
I'm trying to crate some symbolic links, provided the link doesn't already exist. To do that, this is what I've done:

if not os.path.islink(dst_dir):
    os.symlink("src_dir", "dst_dir")

but still I'm getting OSError: [Errno 17] File exists for an existing link. Any idea what am I missing?

another question, how can I use os.symlink() to create force link one using ln -fs <src> <dst> i.e. fore create even if exist. Is it possible somehow?
Thanks in advance. cheers!!!

ln has a -f (force option). See man ln. Also, try this instead as it may not be a symlink

if not os.path.exists(path):

There can be a broken link. It's better to test with lexists:

if not os.path.lexists(destFile):
    os.symlink(sourceFile, destFile)
commented: Nice, but this is an old thread... +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.