Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jooleer committed May 9, 2023
1 parent f86c232 commit abcc98e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions folder_hash_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def generate_file_hash(file_path, hash_algorithm="CRC32"):

return file_hash

# function to recursively get a list of all files in a folder and its subfolders
# get a list of all files in a folder and its subfolders
def get_all_files(folder_path):
global files_amount
all_files = []
Expand All @@ -74,23 +74,24 @@ def get_all_files(folder_path):
all_files.append(file_path)
return all_files


# get amount of files in a folder and its subfolders
def get_files_amount(folder_path):
files_amount = 0
for root, dirs, files in os.walk(folder_path):
for filename in files:
files_amount += 1
return files_amount

# generate hash values for each file in folder_path
def folder_generate_hashes(folder_path):
# generate hash values for each file in folder
folder_hashes = {}
for file_path in get_all_files(folder_path):
file_hash = generate_file_hash(file_path, hash_algorithm)
relative_path = os.path.relpath(file_path, folder_path)
folder_hashes[relative_path] = file_hash
if(args.verbose):
print(f"Generated hash for: {file_path} [{file_hash}]")
logging.info(f"[HASH]: {file_path} -> {file_hash}")
return folder_hashes


Expand Down

0 comments on commit abcc98e

Please sign in to comment.