-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk_file_renamer.py
More file actions
44 lines (30 loc) · 1.13 KB
/
Copy pathbulk_file_renamer.py
File metadata and controls
44 lines (30 loc) · 1.13 KB
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
36
37
38
39
40
41
42
43
44
import os # lets us work with files and folders
# Folder containing your photos
folder_path = os.path.expanduser("~/image_folder") # change if needed
# The new name you want for your files
new_prefix = "Vacation"
# Get a list of all files in the folder
files = os.listdir(folder_path)
# Sort files so they are renamed in order (important!)
files.sort()
# Counter starts at 1
counter = 1
# Go through each file
for filename in files:
# Get full file path
old_file_path = os.path.join(folder_path, filename)
# Skip folders (only rename files)
if os.path.isdir(old_file_path):
continue
# Split filename into name and extension
# Example: "IMG_001.jpg" → ("IMG_001", ".jpg")
name, extension = os.path.splitext(filename)
# Create new filename with leading zeros (001, 002, etc.)
new_name = f"{new_prefix}_{counter:03d}{extension}"
# Create full path for the new file name
new_file_path = os.path.join(folder_path, new_name)
# Rename the file
os.rename(old_file_path, new_file_path)
print(f"Renamed: {filename} → {new_name}")
# Increase counter for next file
counter += 1