python列出目录(包含子目录)下的所有文件

Posted by Tesla9527 on April 26, 2018

脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import os

root_path = r"E:\Movie"
count = 0
result = []
for path, subdirs, files in os.walk(root_path):
    for name in files:
        file = os.path.join(path, name)
        result.append(file)
        count += 1
print("共", count, "个文件")
print('----------------')
for i in result:
    print(i)

运行结果 img