python读取目录下文件并生成日志,,[Python]代码
python读取目录下文件并生成日志,,[Python]代码
[Python]代码
import os from time import strftime stamp=strftime("%Y-%m-%d %H:%M:%S") logfile = 'F://test//m-php-framework//tmp/logs//error_report.log' path = 'F://test//' files = os.listdir(path) bytes = 0 numfiles = 0 for f in files: if f.startswith('t'): info = os.stat(path + f) numfiles +=1 bytes+=info[6] if numfiles > 1: title = 'tiles' else: title = 'file' string = stamp + " -- " + str(numfiles) + " session" +title+","+ str(bytes)+" bytes/n" file = open(logfile,"a") file.writelines(string) file.close()
相关内容
- UTF8文件去BOM,UTF8文件BOM,[Python]代码#!
- python使用sha1加密方法验证文件的有效性,,import hashl
- 批量去除UTF8的Bom标签,utf8bom标签,#!/usr/bin/p
- 周长画圆,周长,[Python]代码im
- for循环,,[Python]代码ki
- 格式化数字及其单位,格式化数字单位,[Python]代码de
- python socket单工聊天工具,pythonsocket单工,socket单工聊天
- 用Python编写的列举所有对称日的小程序--菜鸟写的,请
- python监控网卡流量,python监控网卡,[Python]代码im
- Find the coefficients of the polynomial that fits the specified data
评论关闭