Python: 递归遍历当前目录下面的所有文件

python Logo
image-3282

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os

'''
递归遍历当前目录下面的所有文件.
可以设置过滤的文件.
'''



path="."

# 过滤的文件
entryNameFilter=["app - 副本.json","app.json","App.vue","main.js"]


def scanDir(path=""):
    with os.scandir(path) as it:
        for entry in it:
            if not entry.name.startswith('.') and entry.name not in entryNameFilter and entry.is_file():
                print(entry.path)
                #with open(entry.path,"r",encoding="utf-8") as rrs:
                #   print(rrs.read())
            elif entry.is_dir():
                scanDir(entry.path)



if __name__ == '__main__':
    scanDir(".")

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据