Skip to content

Instantly share code, notes, and snippets.

@lambdan
Created June 18, 2018 20:55
Show Gist options
  • Save lambdan/bfd2a1da64e937c4a31d6ff76e74e673 to your computer and use it in GitHub Desktop.
Save lambdan/bfd2a1da64e937c4a31d6ff76e74e673 to your computer and use it in GitHub Desktop.
rom deorganizer - de-organizes everdrive sets and puts all unique roms in one folder
import os
import sys
import hashlib
import shutil
import time
hashes = []
dupes = []
inputdir = "input/"
outputdir = "output/"
logfile = "deorganizer-" + time.strftime("%Y%m%d%H%M%S") + ".log"
def logPrint(string):
print string
with open(logfile, "a") as myfile:
myfile.write(string + "\n")
def hash_file(filename):
""""This function returns the SHA-1 hash
of the file passed into it"""
# make a hash object
h = hashlib.sha1()
# open file for reading in binary mode
with open(filename,'rb') as file:
# loop till the end of the file
chunk = 0
while chunk != b'':
# read only 1024 bytes at a time
chunk = file.read(1024)
h.update(chunk)
# return the hex representation of digest
return h.hexdigest()
if not os.path.exists(inputdir):
logPrint("error: input dir " + inputdir + " does not exist")
sys.exit(1)
if not os.path.exists(outputdir):
logPrint("making output dir: " + outputdir)
os.makedirs('output/')
for path, subdirs, files in os.walk(inputdir):
for name in files:
src = os.path.join(path, name)
h = hash_file(src)
if h not in hashes:
logPrint("new: " + src + " (" + h + ")")
hashes.append(h)
dest = os.path.join(outputdir, name)
shutil.copy(src, dest)
else:
logPrint("dupe: " + src + " (" + h + ")")
#dupes.append(h)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment