Me4President
Technical User
Hello,
I am trying to count the number of files created per day with a given extension. I am searching a folder recursively.
What I have at the moment counts the number of files per day, but does not include those days where there are no files.
It is probably not as efficient as it should be - any tips on how to improve the loops would be very helpful
I import the out_file to excel to create a chart of the number of files created per day.
Does anyone know a good way of including those days where there were no files created?
Any help greatly appreciated!
I am trying to count the number of files created per day with a given extension. I am searching a folder recursively.
What I have at the moment counts the number of files per day, but does not include those days where there are no files.
Code:
#!/usr/bin/env python
import os, glob, time
print '-'*60
root = raw_input("Folder to search:\n") + '/*'
#print root
ext = '/*.' + raw_input("File type to filter:\n")
file_out = open(raw_input('Fileout name : \n'),"w")
t_start = time.time()
print '-'*26 + 'Running' + '-'*27 # approx 20 seconds / 1000 files
date_file_list = []
for folder in glob.glob(root):
for file in glob.glob(folder + ext):
stats = os.stat(file)
date_file_tuple = time.localtime(stats[8]), file
date_file_list.append(date_file_tuple)
daylist = []
for file in date_file_list:
days = time.strftime("%d/%m/%y", file[0])
daylist += [days]
d = {}
from sets import Set
for i in Set(daylist):
d[i] = daylist.count(i)
file_out.write('%s \t%s \n' % (i,d[i]))
print 'Total no. of %s files = %d\n%.2f seconds runtime\n ' % (ext, len(daylist),time.time()-t_start)
print '='*60
It is probably not as efficient as it should be - any tips on how to improve the loops would be very helpful
I import the out_file to excel to create a chart of the number of files created per day.
Does anyone know a good way of including those days where there were no files created?
Any help greatly appreciated!