|
import hashlib |
|
from pathlib import Path |
|
|
|
|
|
|
|
def md5_hash(file_path): |
|
with open(file_path, 'rb') as f: |
|
file_data = f.read() |
|
md5_hash = hashlib.md5(file_data).hexdigest() |
|
return md5_hash |
|
|
|
def rename_files_in_directory(directory_path): |
|
dir_path = Path(directory_path) |
|
for file_path in dir_path.glob('*.png'): |
|
new_file_name = md5_hash(file_path) + ".png" |
|
new_file_path = file_path.parent / new_file_name |
|
file_path.rename(new_file_path) |
|
print(f"Renamed {file_path} to {new_file_path}") |
|
|
|
if __name__ == "__main__": |
|
directory_path = r"E:\Dataset\XXXXXXX" |
|
rename_files_in_directory(directory_path) |