python遍历文件数

import sys
import os

count = 0

# 遍历文件夹
def walkFile(file):
    for root, dirs, files in os.walk(file):
        # root 表示当前正在访问的文件夹路径
        # dirs 表示该文件夹下的子目录名list
        # files 表示该文件夹下的文件list

        # 遍历文件
        for f in files:
            global count
            count += 1
            #print(os.path.join(root, f))
            os.path.join(root, f)

        # 遍历所有的文件夹
        for d in dirs:
            #print(os.path.join(root, d))
            os.path.join(root, d)
    print("文件数量一共为:", count)

if __name__ == '__main__':
    walkFile(r"/data/dfs/data/")
	
开始时间: 1636442653.8381789
此次分析的目录: /data/dfs/data/
文件数量一共为: 87416186
结束时间: 1636444145.756604
计算时间: 1491.9184250831604

[root@host-40 scripts]# python3 test.py 
文件数量一共为: 87423691

发表评论

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