-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashcalculator_csv.py
35 lines (31 loc) · 1.06 KB
/
hashcalculator_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# A Hash Calculator script written in python for a comma separated value (csv) file output
# Made by redtrillix
# Version: v0.3.0
import hashlib
import os
import csv
import tkinter as tk
from tkinter import filedialog
from datetime import datetime
# Select files using file explorer
root = tk.Tk()
root.withdraw()
files = filedialog.askopenfilenames(title="Select files")
# Calculate hash for each file
hashes = {}
for file_path in files:
with open(file_path, "rb") as f:
file_hash = hashlib.sha256(f.read()).hexdigest()
hashes[file_path] = file_hash
# Write hashes to a CSV file
output_dir = "data"
os.makedirs(output_dir, exist_ok=True)
csv_path = os.path.join(output_dir, "hashes.csv")
file_exists = os.path.isfile(csv_path)
with open(csv_path, "a", newline="") as f:
writer = csv.writer(f)
if not file_exists:
writer.writerow(["File Path", "Hash Value", "Date"])
calculated_date = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
for file_path, file_hash in hashes.items():
writer.writerow([file_path, file_hash, calculated_date])