I have the following code that renames a certain amount of files that have keywords such as: 'Alamo', 'Portland',..., and a handful of other custom names, and I want to put a number next to it: i.e '76-Alamo' / '77-Portland'
Is there a way to repeat the same code N-times by defining the keywords as strings? something like:
Names = ('Alamo', 'Portland', 'Name3',...,)
Number = ('76', '77', '78',...,)
Code:
import os
os.chdir('.')
for file in os.listdir(): clinic, extension = os.path.splitext(file)
for f in os.listdir():
if f.startswith('Alamo'):
old_name = f
new_name = '{}-{}'.format("76", f)
os.rename(old_name, new_name)
for f in os.listdir():
if f.startswith('Portland'):
old_name = f
new_name = '{}-{}'.format("77", f)
os.rename(old_name, new_name)
I appreciate any insight into this. Please let me know if there's any further details I may provide.