import os
def countLines(fname):
try:
with open(fname) as f:
data = f.readlines()
except FileNotFoundError:
print(fname + 'does not exist')
lens = len (data)
print(fname.split('\\')[0]+' has ' + str(lens) + ' lines')
#path ='./testdata'
path ='./'
print(os.getcwd())
for fname in os.listdir(path):
if fname.endswith('.txt'):
file_path = os.path.join(path,fname)
countLines (file_path)
#删除、创建目录
if os.path.exist('./output'):
shutil.rmtree("./output")
os.mkdir("./output")