Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
0bscenity committed May 20, 2024
1 parent dc2df90 commit 2666c99
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions crc32.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
print(f"made by grapes")
import os
import zlib
import csv

def calculate_crc32(file_path):
with open(file_path, "rb") as f:
checksum = 0
for chunk in iter(lambda: f.read(4096), b""):
checksum = zlib.crc32(chunk, checksum)
return checksum & 0xFFFFFFFF


def scan_directory(directory):
"""scan"""
print(f"scaning directory and calculateing the hash(es)")
results = []
for root, _, files in os.walk(directory):
for file in files:
file_path = os.path.join(root, file)
crc32 = calculate_crc32(file_path)
results.append((file, crc32))
return results


def export_to_csv(results, output_file):
print(f"exporting")
"""export"""
with open(output_file, mode="w", newline="", encoding="utf-8") as csv_file:
writer = csv.writer(csv_file)
writer.writerow(["file name", "crc32"])
for file_name, crc32 in results:
writer.writerow([file_name, format(crc32, "08X")])


if __name__ == "__main__":
"""variables"""
# keep r string otherwise it wont scan
directory_to_scan = r"C:\Users\xxxxxxxx" # change directory. might only work if this script is on the same drive as path
output_csv_file = "output_crc.csv"
results = scan_directory(directory_to_scan)
export_to_csv(results, output_csv_file)

print(f"list has been exported to {output_csv_file}")

0 comments on commit 2666c99

Please sign in to comment.