|
|

楼主 |
发表于 2019-3-20 06:04:16
|
显示全部楼层
不知为何:用代码功能发的时候,有的\\变成了\,我重新发一下。
import os
import easygui as g
def filesearch (filepath):
f1 = os.listdir(filepath) ##打开初始文件夹##
count = 0 ##用于统计行数##
list1 = [] ##用于列出所有py文件名##
for each in f1:
if os.path.splitext(each)[1] == ".py": ##若该文件是py 文件则打开文件,统计行数。##
list1.append(filepath + "\\" +each + " \n")
f = open (filepath+"\\" +each, encoding='UTF-8')
for eachline in f:
count = count +1
f.close()
if os.path.isdir(filepath + "\\"+ each) :##若该文件文件夹,则用递归函数进入文件夹统计行数。##
filesearch (filepath+ "\\"+ each)
os.chdir(os.pardir)
return list1
return count
msg = "Total %s lines" % count + "Progress: " + str(count/1E6) +"\n There are " +\
str(1E6-count) + " lines left."
g.textbox(msg, "Final Results", list1) ##显示结果。##
path = g.diropenbox()
filesearch(path)
|
|