import os
path = os.path.abspath(".")+'\\'
print(path)
count=0
def counter(path):
# 获取所有文件
file_list = os.listdir(path)
global count
for file in file_list:
if file != "__init__.py" and ".py" in file and ".pyc" not in file:
flag = 0
print(path + file)
with open(path + file, 'r', encoding="utf8") as f:
while (True):
res = f.readline()
if flag ==5:
break
if res =="":
flag+=1
else:
count+=1
if "." not in file and file!="venv":
temp = path+file+"\\"
counter(temp)
counter(path)
print(count)
结果:
打印的文件忽略了
12337