1
I am trying to perform the following function: Rename a list of files according to their modification date, from the oldest to the newest. The name of the files I have in an Excel list and the intention is to rename the oldest file with the 1st line of excel, second oldest file with the 2nd line of Excel. The code I have today renames only a random file with the first line and after the error:
import pandas as pd
import os
from datetime import datetime
#lista dos links
urls = pd.read_excel(r'C:/Users/u0000008/Documents/Excel/Controle de Janelas - Comissões - 2a Janela.xlsm', sheet_name ='Respostas',)
path = r'C:\Users\u0000008\Downloads'
files = os.listdir(path)
mod_time = os.path.getmtime(r'C:\Users\u0000008\Downloads')
print(datetime.fromtimestamp(mod_time))
lista_nomes =[]
for Nome, file in enumerate(files):
lista_nomes =[]
for Nome in urls ['Digite e selecione o nome ou o código de seu escritório abaixo:']:
os.rename(os.path.join(path, file), os.path.join(path, ''.join([str(Nome), '.pdf'])))