Advertisement
Peaser

rename all files to their hash

Mar 20th, 2015
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. import os, sys, hashlib
  2.  
  3. def main():
  4.     thisdir = os.listdir(os.getcwd())
  5.     thisfile = os.path.split(sys.argv[0])[1]
  6.     files = [i for i in thisdir if i != thisfile]
  7.     for file in files:
  8.  
  9.         filehash = hashlib.md5(open(file, "rb").read()).hexdigest()
  10.         extension = os.path.splitext(file)[1]
  11.         os.rename(file, filehash+extension)
  12.  
  13.         del(filehash)
  14.         del(extension) #memory
  15.        
  16. if __name__ == "__main__":
  17.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement