Create a Python program to rename the Excel spreadsheets (found in the folder attached to this assignment) to add SCC in front of each file name. Save the newly named files in a new directory.
I can put the link in there for it
import os, os.path
path = 'c:/' # Specify directory to process
n = 1
ren_path = os.path.join(path, 'xls_renamed')
ren_path_num = ''
while os.path.exists(ren_path + ren_path_num):
ren_path_num = str(n)
n += 1
ren_path += ren_path_num
os.mkdir(ren_path)
if path:
os.chdir(path)
for file in os.listdir():
if os.path.isfile(file):
if file.endswith('.xls') or file.endswith('.xlsx'):
os.system(f'copy {file} {os.path.join(ren_path, "SCC" + file)}')
Comments
Leave a comment