-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (20 loc) · 866 Bytes
/
main.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
import os
def get_last_number():
while True:
try:
last_number = int(input("Podaj ostatni numer pliku, od którego zacząć numerację: "))
return last_number
except ValueError:
print("bląd liczba całkowita")
folder_path = os.path.join("data", "data")
files = [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
files.sort()
unnumbered_files = [f for f in files if not f.split('.')[0].isdigit()]
start_number = get_last_number()
for index, file_name in enumerate(unnumbered_files):
file_extension = os.path.splitext(file_name)[1]
new_name = f"{start_number + index:03d}{file_extension}"
old_path = os.path.join(folder_path, file_name)
new_path = os.path.join(folder_path, new_name)
os.rename(old_path, new_path)
print("Numerowanie zakończone!")