基本信息
源码名称:python统计一个文件夹内所有txt的行数和
源码大小:0.67KB
文件格式:.py
开发语言:Python
更新时间:2020-10-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
统计txt文件所有行数的和,适合几十兆几百兆且上百上千个文件手算不过来时使用

import time
import os

def getcount():   
    dirpath=input("请输入要计算的文件夹如(d:\\user):")
#    dirpath=os.path.dirname(os.path.abspath(__file__)) "\\ipbak3"
    iptxtlist=os.listdir(dirpath)

    ipstrs1=[]
    filecounts=len(iptxtlist)
    print(filecounts)
    counts=0
    for j in range(0,filecounts):
         filepaths=dirpath "\\" iptxtlist[j]
         with open(filepaths, 'r') as f:
          try:
           for line in f.readlines():
            counts=counts 1
          except Exception:
           counts=counts 1
         print(counts)
    print(counts)
    input("按任意键继续")


if __name__ == '__main__':
    getcount()