[英]How to check if file is not symlink in python
当前运行的代码是:
for y in checkdirlist:
if (y in no_exec or y.endswith(".ebuild")) and \
stat.S_IMODE(os.stat(os.path.join(checkdir, y)).st_mode) & 0o111:
stat失败,并显示符号链接文件。
我想添加一些检查y是否为符号链接。
lstat
解决了系统错误的问题,但总体上还没有结束
Traceback (most recent call last):
File "/usr/bin/repoman", line 1385, in <module>
myaux = dict(zip(allvars, portdb.aux_get(cpv, allvars)))
File "/usr/lib/portage/pym/portage/dbapi/porttree.py", line 435, in aux_get
myebuild, mylocation = self.findname2(mycpv, mytree)
File "/usr/lib/portage/pym/portage/dbapi/porttree.py", line 308, in findname2
raise InvalidPackageName(mycpv)
portage.exception.InvalidPackageName: dev-haskell/.#hakyll-9999
我想过滤那些文件,所以我需要知道哪些是符号链接。
从文档中,您可能需要os.path.islink :
os.path.islink(路径)
Return True if path refers to a directory entry that is a symbolic link. Always False if symbolic links are not supported.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.