Advertisement
Guest User

Almost Duplicate.py

a guest
Jul 29th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. import glob,os,pdb,time
  2.  
  3. class File_:
  4.  
  5.     def __init__(self,name_,codes_,codeLength_,shortName_):
  6.         self.name=name_
  7.         self.codes=codes_
  8.         self.codeLength=codeLength_
  9.         self.shortName=shortName_
  10.  
  11.  
  12. metaFiles=[]
  13. files=[]
  14. delete=[]
  15. tmpList=[]
  16.  
  17. print("Searcing for files...")
  18. files=glob.glob("*")
  19. print("Found "+str(len(files))+" files!")
  20. files.sort()
  21.  
  22. chars=[]
  23.  
  24. tmpCodes=0
  25. tmpCodeLength=0
  26. tmpShortName=''
  27. shortNameDone=0
  28.  
  29. num=0
  30. curFile=1
  31. tmp=''
  32.  
  33. print("Gathering information...")
  34.  
  35. for x in files:
  36.     print("Analyzing file "+str(curFile)+"/"+str(len(files)))
  37.  
  38.     #pdb.set_trace()
  39.     fullName=str(x)
  40.     chars=list(fullName)
  41.  
  42.     while num<=len(chars)-1:
  43.         #print(chars[num])
  44.  
  45.         if chars[num] =="(" or chars[num]=="[":
  46.             tmpCodes+=1
  47.             shortNameDone=1
  48.             while chars[num]!=")" and chars[num]!="]":
  49.                 num+=1
  50.  
  51.                 tmpCodeLength+=1
  52.         else:
  53.             if not shortNameDone:
  54.                 tmpShortName=tmpShortName+chars[num]
  55.             num+=1
  56.     metaFiles.append(File_(fullName,tmpCodes,tmpCodeLength,tmpShortName))
  57.  
  58.     tmpCodes=0
  59.     tmpCodeLength=0
  60.     tmpShortName=''
  61.     shortNameDone=0
  62.     num=0
  63.  
  64.     tmp=''
  65.     curFile+=1
  66.  
  67. print("Searching for duplicates...")
  68.  
  69. for x in metaFiles:
  70.     for y in metaFiles:
  71.         if y!=x:
  72.             if y.shortName==x.shortName:
  73.                 if y.codes<x.codes:
  74.                     delete.append(y.name)
  75.                 else:
  76.                     if y.codeLength<x.codeLength:
  77.                         delete.append(y.name)
  78.                     else:
  79.                         pass
  80.                         '''
  81.                        print("What the? Two files are the same but not the same.")
  82.                        print("The files are:")
  83.                        print(str(x.name))
  84.                        print(str(y.name))
  85.                        input("Hit enter to continue...")
  86.                        '''
  87.  
  88. print("About to delete "+str(len(delete))+" files. Hit enter to continue...")
  89. input()
  90.  
  91. for x in delete:
  92.     try:
  93.         os.remove(str(x))
  94.     except:
  95.         print("Problem removing "+str(x))
  96.  
  97. print("Success!")
  98. input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement