Advertisement
cacodemon665

Untitled

Oct 25th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. import os
  2. import sys
  3. import hashlib
  4.  
  5. BUF_SIZE = 65536  # lets read stuff in 64kb chunks!
  6.  
  7. hashStash = open('E:\\thread scraping\\hashStash.txt', 'r+')
  8. stashListed = []
  9. for line in hashStash.readlines():
  10.     stashListed.append(line.rstrip())
  11. for element in stashListed:
  12.     print(element)
  13.  
  14. def check(checkValue, currentFilename):
  15.     unique = True
  16.     for line in stashListed:
  17.         if checkValue in line:
  18.             os.remove('E:\\thread scraping\\to sort\\' + currentFilename)
  19.             print('File removed.')
  20.             unique = False
  21.     if unique == True:
  22.         hashStash.write(checkValue + '\n')
  23.         os.rename('E:\\thread scraping\\to sort\\' + currentFilename, 'E:\\thread scraping\\the pit\\' + currentFilename)
  24.         print('File moved.')
  25. #    input('Press any key to terminate the check function...')
  26.  
  27. fileList = []
  28. for dirname, dirnames, filenames in os.walk('E:\\thread scraping\\to sort\\'):
  29.     for filename in filenames:
  30.         fileList.append(os.path.join(filename))
  31. #print(fileList)
  32. print(range(len(fileList)))
  33.  
  34. for i in range(len(fileList)):
  35.     currentFilename = fileList[i]
  36.  
  37.     md5 = hashlib.md5() # !!!!!!!!!
  38.     sha1 = hashlib.sha1()
  39.  
  40.     with open('E:\\thread scraping\\to sort\\' + currentFilename, 'rb') as f:
  41.         while True:
  42.             data = f.read()
  43.             if not data:
  44.                 break
  45.             md5.update(data)
  46.             sha1.update(data)
  47.     size = os.path.getsize('E:\\thread scraping\\to sort\\' + currentFilename)
  48.     print("MD5: {0}".format(md5.hexdigest()))
  49.     print("SHA1: {0}".format(sha1.hexdigest()))
  50.     print(size)
  51.     md5Value = format(md5.hexdigest())
  52.     checkValue = md5Value + '___' + str(size)
  53.     print('Current hash/size values: ' + checkValue)
  54.     check(checkValue, currentFilename)
  55.  
  56. input('Press any key to continue...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement