Created
November 2, 2023 05:50
-
-
Save zengxinhui/339c9f44644751a7a89f591d4fe5b582 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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