代码如下
将遍历出来的路径全部添加到列表中:
def get_all_abs_path(source_dir):
path_list = []
for fpathe, dirs, fs in os.walk(source_dir):
for f in fs:
p = os.path.join(fpathe, f)
path_list.append(p)
return path_list
将遍历出来的路径全部添加到列表中:
def get_all_abs_path(source_dir):
path_list = []
for fpathe, dirs, fs in os.walk(source_dir):
for f in fs:
p = os.path.join(fpathe, f)
path_list.append(p)
return path_list
《python通过os.walk() 遍历出多级目录下所有文件绝对路径.doc》
下载本文的Word格式文档,以方便收藏与打印。