Advertisement
Guest User

Almost Duplicate.py

a guest
Jul 31st, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 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. noDelete=[]
  16. tmpList=[]
  17.  
  18. accept=0
  19.  
  20. while True:
  21.  
  22.     metaFiles[:]=[]
  23.     files[:]=[]
  24.     delete[:]=[]
  25.     noDelete[:]=[]
  26.     tmpList[:]=[]
  27.  
  28.     print("Searcing for files...")
  29.     files=glob.glob("*")
  30.     print("Found "+str(len(files))+" files!")
  31.     files.sort()
  32.  
  33.     chars=[]
  34.  
  35.     tmpCodes=0
  36.     tmpCodeLength=0
  37.     tmpShortName=''
  38.     shortNameDone=0
  39.  
  40.     num=0
  41.     curFile=1
  42.     tmp=''
  43.  
  44.     print("Gathering information...")
  45.  
  46.     for x in files:
  47.         print("Analyzing file "+str(curFile)+"/"+str(len(files)))
  48.  
  49.         #pdb.set_trace()
  50.         fullName=str(x)
  51.         chars=list(fullName)
  52.  
  53.         while num<=len(chars)-1:
  54.             #print(chars[num])
  55.  
  56.             if chars[num] =="(" or chars[num]=="[":
  57.                 tmpCodes+=1
  58.                 shortNameDone=1
  59.                 while chars[num]!=")" and chars[num]!="]":
  60.                     num+=1
  61.  
  62.                     tmpCodeLength+=1
  63.             else:
  64.                 if not shortNameDone:
  65.                     tmpShortName=tmpShortName+chars[num]
  66.                 num+=1
  67.         metaFiles.append(File_(fullName,tmpCodes,tmpCodeLength,tmpShortName))
  68.  
  69.         tmpCodes=0
  70.         tmpCodeLength=0
  71.         tmpShortName=''
  72.         shortNameDone=0
  73.         num=0
  74.  
  75.         tmp=''
  76.         curFile+=1
  77.  
  78.     print("Searching for duplicates...")
  79.  
  80.     num=0
  81.     checking=0
  82.  
  83.     while num<len(metaFiles)-1:
  84.         if not checking:
  85.             tmp=metaFiles[num].shortName
  86.             path=metaFiles[num].name
  87.         if num+1!=len(metaFiles)-1:
  88.             if metaFiles[num+1].shortName==tmp:
  89.                 noDelete.append(path)
  90.                 delete.append(metaFiles[num+1].name)
  91.             else:
  92.                 checking=1
  93.         if metaFiles[num+1].name!=tmp:
  94.             checking=0
  95.         num+=1
  96.  
  97.     if not accept:
  98.         print("About to delete "+str(len(delete))+" files. Hit enter to continue...")
  99.         input()
  100.         accept=1
  101.     else:
  102.         print("Deleting "+str(len(delete))+" files...")
  103.  
  104.     if len(delete)==0:
  105.         break
  106.     for x in delete:
  107.         try:
  108.             if x not in noDelete:
  109.                 os.remove(str(x))
  110.         except:
  111.             print("Problem removing "+str(x))
  112.  
  113. print("Success!")
  114. input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement