Python os.walk +关注符号链接 [英] Python os.walk + follow symlinks
本文介绍了Python os.walk +关注符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得此代码以遵循python 2.6中的符号链接?
How do I get this piece to follow symlinks in python 2.6?
def load_recursive(self, path):
for subdir, dirs, files in os.walk(path):
for file in files:
if file.endswith('.xml'):
file_path = os.path.join(subdir, file)
try:
do_stuff(file_path)
except:
continue
推荐答案
将followlinks
设置为True
.这是os.walk
方法的第四个参数,如下所示:
Set followlinks
to True
. This is the fourth argument to the os.walk
method, reproduced below:
os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
此选项是在Python 2.6中添加的.
This option was added in Python 2.6.
这篇关于Python os.walk +关注符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文