Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- import os
- import sys
- import stat
- import re
- import itertools
- dirname = sys.argv[1]
- d = os.getcwd()
- os.chdir(dirname)
- all_files = []
- fnames = os.listdir(dirname)
- dupes = []
- all_prefix = []
- all_suffix = []
- for line in fnames:
- if "Data_" in line:
- matches = re.findall(r"^Data_[a-z]{1,2}_FlatNTuple_.[0-9]{0,3}_[0-9]{1}_[0-9a-zA-Z]{3}\.root" ,line)
- #matches = re.findall(r"^Data_[a-z]{1,2}_FlatNTuple_.[0-9]{0,3}_" ,line)
- matches_prefix = re.findall(r"^Data_[a-z]{1,2}_FlatNTuple_.[0-9]{0,3}_" ,line)
- matches_prefix = str(matches_prefix[0])
- matches = str(matches[0])
- matches_suffix = matches[-10:]
- all_prefix.append(matches_prefix)
- all_suffix.append(matches_suffix)
- cleaned_files = dict(itertools.izip(all_prefix,all_suffix))
- os.chdir(d)
- all_files = dict(itertools.izip(all_suffix,all_prefix))
- cleaned_values = []
- filesToRemove = []
- for key in cleaned_files.keys():
- cleaned_values.append(cleaned_files[key])
- for key in all_files.keys():
- #print key
- if key not in cleaned_values:
- filesToRemove.append(str(all_files[key])+str(key))
- for i in filesToRemove:
- dupes.append(os.path.join(dirname, i))
- for i in dupes:
- print "rm "+str(i)
Add Comment
Please, Sign In to add comment