File size: 593 Bytes
0b9f9a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os

# Set your folder path
folder_path = "/Users/louis/Downloads/llm_course"
# Get all filenames from the folder
filenames = os.listdir(folder_path)

# Iterate through each filename
for filename in filenames:
    last_space_index = filename.rfind(" ")

    # If a space is found, rename the file
    if last_space_index != -1:
        new_filename = filename[:last_space_index]
        old_path = os.path.join(folder_path, filename)
        new_path = os.path.join(folder_path, new_filename)

        os.rename(old_path, new_path)
        print(f"Renamed {filename} to {new_filename}")