import csv
import sys
import time
import os
def traverse_directory(path):
dirCnt=0
fileCnt=0
for root, dirs, files in os.walk(path):
print(files)
for name in files:
print(name)
fileCnt+=1
#file_path = os.path.join(root, name)
#print(file_path)
for name in dirs:
dirCnt+=1
dir_path = os.path.join(root, name)
#print(file_path)
return dirCnt,fileCnt
if __name__ == "__main__" :
dirCnt,fileCnt = traverse_directory("./")
strCnt = "目录数量:" + str(dirCnt)
print(strCnt)
strCnt = "文件数量:" + str(fileCnt)
print(strCnt)
python遍历目录代码
于 2024-09-06 18:00:22 首次发布