Skip to content

Instantly share code, notes, and snippets.

@zengxinhui
Created November 2, 2023 05:50
Show Gist options
  • Save zengxinhui/339c9f44644751a7a89f591d4fe5b582 to your computer and use it in GitHub Desktop.
Save zengxinhui/339c9f44644751a7a89f591d4fe5b582 to your computer and use it in GitHub Desktop.
import hashlib, os, sqlite3, sys
con = sqlite3.connect("hash.db")
cur = con.cursor()
cur.execute("delete from files")
for root, dirs, files in os.walk(sys.argv[1]):
for file in files:
filename = root + "/" + file
with open(filename, 'br') as f:
size = os.stat(filename).st_size
if size > 4194304:
hash = hashlib.sha256(f.read(8192)).hexdigest()
cur.execute(f"""insert into files values ("{hash}", {size}, "{root}", "{file}")""")
con.commit()
con.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment