forked from sachinpc1993/walert
-
Notifications
You must be signed in to change notification settings - Fork 1
/
renaming.py
26 lines (20 loc) · 958 Bytes
/
renaming.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
import os
def rename_files_in_folder(folder_path, old_substr, new_substr):
try:
files = os.listdir(folder_path)
for filename in files:
if old_substr in filename:
new_filename = filename.replace(old_substr, new_substr)
old_filepath = os.path.join(folder_path, filename)
new_filepath = os.path.join(folder_path, new_filename)
os.rename(old_filepath, new_filepath)
print(f"File '{filename}' renamed to '{new_filename}'.")
except FileNotFoundError:
print(f"Folder '{folder_path}' not found.")
# Specify the folder path containing the files
folder_path = "input/intent/utterances/"
# Specify the substring to be removed and the new substring
old_substring = "-utterances"
new_substring = ""
# Call the function to rename files in the folder
rename_files_in_folder(folder_path, old_substring, new_substring)