|
import os
|
|
import re
|
|
|
|
def rename_files(start_num):
|
|
|
|
files = [f for f in os.listdir() if os.path.isfile(f)]
|
|
|
|
|
|
regex = re.compile(r'(\d+)')
|
|
files_with_numbers = [(f, regex.search(f)) for f in files]
|
|
|
|
|
|
files_with_numbers = [(f, match) for f, match in files_with_numbers if match]
|
|
|
|
|
|
files_with_numbers.sort(key=lambda x: int(x[1].group()))
|
|
|
|
|
|
for i, (filename, match) in enumerate(files_with_numbers):
|
|
|
|
new_num = start_num + i
|
|
|
|
|
|
new_filename = regex.sub(str(new_num), filename)
|
|
|
|
|
|
os.rename(filename, new_filename)
|
|
print(f'Renamed: {filename} -> {new_filename}')
|
|
|
|
|
|
start_num = int(input("Enter the starting number: "))
|
|
|
|
|
|
rename_files(start_num)
|
|
|