Guest User

Untitled

a guest
Sep 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #! /usr/bin/python
  2.  
  3. import os
  4. import sys
  5. import stat
  6. import re
  7. import itertools
  8.  
  9. dirname = sys.argv[1]
  10. d = os.getcwd()
  11. os.chdir(dirname)
  12.  
  13. all_files = []
  14. fnames = os.listdir(dirname)
  15.  
  16. dupes = []
  17. all_prefix = []
  18. all_suffix = []
  19.  
  20. for line in fnames:
  21.     if "Data_" in line:
  22.         matches = re.findall(r"^Data_[a-z]{1,2}_FlatNTuple_.[0-9]{0,3}_[0-9]{1}_[0-9a-zA-Z]{3}\.root" ,line)
  23.         #matches = re.findall(r"^Data_[a-z]{1,2}_FlatNTuple_.[0-9]{0,3}_" ,line)
  24.         matches_prefix = re.findall(r"^Data_[a-z]{1,2}_FlatNTuple_.[0-9]{0,3}_" ,line)
  25.         matches_prefix = str(matches_prefix[0])
  26.         matches = str(matches[0])
  27.         matches_suffix = matches[-10:]
  28.         all_prefix.append(matches_prefix)
  29.         all_suffix.append(matches_suffix)
  30. cleaned_files = dict(itertools.izip(all_prefix,all_suffix))
  31.  
  32. os.chdir(d)
  33. all_files = dict(itertools.izip(all_suffix,all_prefix))
  34.  
  35. cleaned_values = []
  36. filesToRemove = []
  37. for key in cleaned_files.keys():
  38.     cleaned_values.append(cleaned_files[key])
  39. for key in all_files.keys():
  40.     #print key
  41.     if key not in cleaned_values:
  42.         filesToRemove.append(str(all_files[key])+str(key))
  43.  
  44.  
  45. for i in filesToRemove:
  46.     dupes.append(os.path.join(dirname, i))
  47.  
  48. for i in dupes:    
  49.     print "rm "+str(i)
Add Comment
Please, Sign In to add comment