我试图编写一个python2函数,它将递归地遍历给定目录的整个目录结构,并打印出结果。在
全部不用手术室步行在
到目前为止,我得到的是:
test_path = "/home/user/Developer/test"
def scanning(sPath):
output = os.path.join(sPath, 'output')
if os.path.exists(output):
with open(output) as file1:
for line in file1:
if line.startswith('Final value:'):
print line
else:
for name in os.listdir(sPath):
path = os.path.join(sPath, name)
if os.path.isdir(path):
print "'", name, "'"
print_directory_contents(path)
scanning(test_path)
这是我目前得到的,脚本没有进入新文件夹:
^{pr2}$问题是,它不会深入到一个目录下。我还想能够直观地指出什么是目录,什么是文件
尝试使用递归函数
抱歉,如果这不符合你的例子,但我很难理解你想做什么。在
用递归来试试这个 它非常简单,代码更少
试试这个:
我在windows上工作,验证是否还在unix上工作。 改编自: http://codegists.com/snippet/python/print_directory_contentspy_skobnikoff_python
相关问题 更多 >
编程相关推荐