-
Notifications
You must be signed in to change notification settings - Fork 1
/
renamed.py
29 lines (20 loc) · 1014 Bytes
/
renamed.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
import os
def bulk_rename_images(directory):
# Get a list of all files in the directory
files = os.listdir(directory)
# Filter out only image files (you can adjust the extensions as needed)
image_files = [f for f in files if f.lower().endswith(('.jpg', '.jpeg', '.png', '.gif'))]
# Sort the image files for consistent numbering
image_files.sort()
# Counter for numbering
counter = 1
for image_file in image_files:
old_path = os.path.join(directory, image_file)
new_path = os.path.join(directory, f"{counter}.jpg") # Adjust the extension if needed
os.rename(old_path, new_path)
print(f"Renamed {image_file} to {counter}.jpg")
counter += 1
# Specify the directory where your images are located
directory = "C:/Users/R. TARUN NAYAKA/Pictures/tarun records/cert2"
# Call the function to perform the renaming the given files in numeric order
bulk_rename_images(directory)