-
Notifications
You must be signed in to change notification settings - Fork 0
/
cextension.py
31 lines (24 loc) · 1010 Bytes
/
cextension.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
27
28
29
30
31
import os
import time
def rename_files(folder_path, include_subfolders, input_format, output_format):
count = 0
start_time = time.time()
for root, dirs, files in os.walk(folder_path):
if not include_subfolders and root != folder_path:
break
for file in files:
if file.lower().endswith(input_format):
old_file_path = os.path.join(root, file)
new_file_path = os.path.join(root, file[:file.rfind(".")] + output_format)
os.rename(old_file_path, new_file_path)
count += 1
end_time = time.time()
elapsed_time = end_time - start_time
return count, elapsed_time
# Example usage
folder_path = "path/to/folder"
include_subfolders = True
input_format = ".ts"
output_format = ".mp4"
count, elapsed_time = rename_files(folder_path, include_subfolders, input_format, output_format)
print(f"File renaming completed!\nTotal files renamed: {count}\nElapsed time: {elapsed_time:.2f} seconds")