按日期分组并在Python中计算特定值

时间:2017-12-04 15:08:39

标签: python count

我想计算每天产生的文件数量。我有输出文件的代码,但我不知道用什么来按日期对文件进行分组并计算它们。

我该怎么做?

import xlwt
import os
import datetime

now = datetime.date.today()



extension = '.txt'

envs = ['<foldername>']



for env in envs:
    file_path = '\\<servername>\<folder>\' + env + '\<folder>\'
    for files in os.listdir(file_path):
        list = []
        list.append(os.path.getmtime(file_path+files))
        for list_code_date in list:
            listt=[]
            listt.append(datetime.datetime.fromtimestamp(list_code_date).strftime('%d-%m-%Y'))
        for list_hn_date in listt:
            print list_hn_date

1 个答案:

答案 0 :(得分:0)

我使用的是os.popen,因为我最初使用的代码是一个简单的任务:

dates = os.popen('cmd /c "cd /d R:\\'+env+'\\Crash_Reports && C:\\cygwin64\\bin\\find_linux.exe . -type f -printf "%TY-%Tm-%Td\\n" | sort |C:\\cygwin64\\bin\\uniq -c | C:\\cygwin64\\bin\\gawk "{print $2}""').read()
相关问题