Answer to Question #264056 in Python for Zach

Question #264056

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


1
Expert's answer
2021-11-10T11:53:21-0500
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)}')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS