-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-renamer-script.py
32 lines (24 loc) · 1.3 KB
/
image-renamer-script.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
import os
import datetime
def rename_images(root_directory, log_file_path):
with open(log_file_path, 'a') as log_file:
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
log_file.write(f"=== Renaming Log ({timestamp}) ===\n")
for root, _, files in os.walk(root_directory):
for filename in files:
if filename.endswith("-min.png"):
original_path = os.path.join(root, filename)
# Remove the "-min" suffix
new_filename = filename.replace("-min", "")
new_path = os.path.join(root, new_filename)
# Rename the file
os.rename(original_path, new_path)
# Log the renaming activity
log_message = f"Renamed: {filename} to {new_filename}\n"
log_file.write(log_message)
print(log_message.strip())
# Replace 'your_root_directory_path' with the path to the root directory containing your images and subdirectories
root_directory_path = 'your_root_directory_path'
# Replace 'rename_log.txt' with the desired name of the log file
log_file_path = 'rename_log.txt'
rename_images(root_directory_path, log_file_path)