Created
September 20, 2013 12:49
-
-
Save AyumuKasuga/6636974 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from collections import defaultdict | |
LIMIT = 1 | |
file_dict = defaultdict(list) | |
remove_files = [] | |
for filename in os.listdir('.'): | |
start = filename.split('-')[0] | |
file_dict[start].append(filename) | |
for group, filelist in file_dict.iteritems(): | |
remove_files.extend(sorted(filelist, reverse=True)[LIMIT:]) | |
print "files for remove: {0}".format(", ".join(remove_files)) | |
for remove_file in remove_files: | |
os.remove(remove_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment