属性的Python os.walk()循环目录
我有一个文本文件,每行1、2、3都包含目录名,我如何迭代文本文件并将结果插入os.walk 到目前为止,我已经属性的Python os.walk()循环目录,python,python-2.7,Python,Python 2.7,我有一个文本文件,每行1、2、3都包含目录名,我如何迭代文本文件并将结果插入os.walk 到目前为止,我已经 import os from os import listdir dir_file = open("list.txt", "r") for root, dirs, files in os.walk(dir_file): for name in files: print(os.path.join(root, name)) for name in dir
import os
from os import listdir
dir_file = open("list.txt", "r")
for root, dirs, files in os.walk(dir_file):
for name in files:
print(os.path.join(root, name))
for name in dirs:
print(os.path.join(root, name))
我使用了while循环和for循环以及if语句的组合来尝试执行这项操作,但我运气不好
有什么帮助吗
谢谢那么:
rdf = []
for fff in dir_file:
for r, d, f in os.walk(fff):
rdf.append(r, d, f)
我通过以下方式解决了这个问题:
import os
from os import listdir
dir_file = open("list.txt", "r")
for x in dir_file:
for root, dirs, files in os.walk(x.strip()):
for name in files:
print(os.path.join(root, name))
for name in dirs:
print(os.path.join(root, name))
谢谢:您必须先迭代dir\u文件