-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenamer.py
More file actions
26 lines (18 loc) · 797 Bytes
/
renamer.py
File metadata and controls
26 lines (18 loc) · 797 Bytes
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
import os
def rename_files(folder_path, prefix):
files = os.listdir(folder_path)
for index, file in enumerate(files):
# Get the file extension
_, extension = os.path.splitext(file)
# Construct the new file name
new_name = f"{prefix}{index + 1}{extension}"
# Construct the full paths of the old and new names
old_path = os.path.join(folder_path, file)
new_path = os.path.join(folder_path, new_name)
# Rename the file
os.rename(old_path, new_path)
print(f"Renamed {file} to {new_name}")
folder_path = 'E:\Documents\School\Spring 2023\CS 4200 Artificial Intelligence\FINALPROJECTFROMSCRATCH\/raw-img\squirrel'
prefix = 'squirrel'
# Call the function to rename the files
rename_files(folder_path, prefix)