admin管理员组文章数量:1313006
I have source and link paths. I'm trying to create a symlink, but must be misunderstanding how its used. Let's say
source = '/var/source/things/'
link = '/var/link/'
When I use os.symlink(source, link)
Initially I received an error
FileNotFoundError: [Errno 129] EDC5129I No such file or directory.: '/var/source/things/' -> '/var/link/'
Ok, so I'll put in something to create the directory if it doesn't exist.
if not os.path.exists(link):
os.makedirs(link)
Re-run and now receive:
FileExistsError: [Errno 117] EDC5117I File exists.: '/var/source/things/' -> '/var/link/'
So if the directory doesn't exist it fails and if the directory does exist it also fails?
We have a bash script that uses
ln -sf $source/* $link
Which creates symlinks for all folders within 'source' and was hoping python would be just as easy. But as I mentioned before, I'm misunderstanding something here.
I have source and link paths. I'm trying to create a symlink, but must be misunderstanding how its used. Let's say
source = '/var/source/things/'
link = '/var/link/'
When I use os.symlink(source, link)
Initially I received an error
FileNotFoundError: [Errno 129] EDC5129I No such file or directory.: '/var/source/things/' -> '/var/link/'
Ok, so I'll put in something to create the directory if it doesn't exist.
if not os.path.exists(link):
os.makedirs(link)
Re-run and now receive:
FileExistsError: [Errno 117] EDC5117I File exists.: '/var/source/things/' -> '/var/link/'
So if the directory doesn't exist it fails and if the directory does exist it also fails?
We have a bash script that uses
ln -sf $source/* $link
Which creates symlinks for all folders within 'source' and was hoping python would be just as easy. But as I mentioned before, I'm misunderstanding something here.
Share Improve this question asked Feb 1 at 3:29 AlexHAlexH 735 bronze badges1 Answer
Reset to default 2Can you remove "/" at the end under link and try once
source = '/var/source/things/'
link = '/var/link'
apart from that, I don't see any issues in your code.
本文标签: pythonossymlink fails when directory exists and when directory doesn39t existStack Overflow
版权声明:本文标题:python - os.symlink fails when directory exists and when directory doesn't exist - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741888467a2403163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论