Untitled
unknown
python
2 years ago
766 B
8
Indexable
import os
parent_dir = 'dataset/nonviolence'
try:
for folder_name in os.listdir(parent_dir):
if folder_name.startswith("Sequence_"):
current_path = os.path.join(parent_dir, folder_name)
new_folder_name = folder_name.replace("Sequence_", "Renamed_Sequence_")
new_path = os.path.join(parent_dir, new_folder_name)
os.rename(current_path, new_path)
print(f"Folder renamed from '{current_path}' to '{new_path}' successfully.")
except FileNotFoundError:
print(f"Error: The directory '{parent_dir}' does not exist.")
except PermissionError:
print(f"Error: Permission denied to rename folders in '{parent_dir}'.")
except Exception as e:
print(f"An error occurred: {e}")
Editor is loading...
Leave a Comment