Spaces:
Running
Running
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}") | |