hey guy n girls i hope one of you can help me with this.
plan of action is to : create a python script to...
sort a list of files from a directory into sorted list with most recent modified date at the top.
then I want to get rid of all the duplicate files with the same date.
then I want to pull the top 6 files and delete the rest.
i have worked out how to order the list and sort it,
but when i put it in to a set it still shows all the files how do i tell the set that it needs to work by the date not the name?
# sorts files by modifed date,
# pulls 6 most recent files,
# and delete all others.
#created by dan holding v0.1 (03 Aug 2010)
import os, glob, time, sets
root = '.'
date_file_list = []
date_file_set = []
for folder in glob.glob(root):
print "folder =", folder
for file in glob.glob(folder + '\*.txt*'):
# select the type of file, for instance *.bat or all files *.*
stats = os.stat(file)
lastmod_date = time.localtime(stats[8])
date_file_tuple =lastmod_date, file
date_file_list.append(date_file_tuple)
date_file_list.sort(reverse = True)
# latest modifed date now first
date_file_set.append(date_file_list)
print (len(date_file_list))
for file in date_file_list:
folder, file_name = os.path.split(file[1])
file_date = time.strftime("%m/%d/%y %H:%M:%S", file[0])
# convert date tuple to MM/DD/YYYY HH:MM:SS format
print "%-40s %s" % (file_name, file_date)