Every morning I have to copy yesterday's file, paste it as today's file, refresh a PowerQuery via a macro and save the file with today's date.
I'm beginning to learn Python and I have found a way to copy and paste the file with today's date. Because I want it to run with no actual file name constraints, I want the code to be able to select the most recently modified file, which would be always be yesterday's file, copy it with today's date in the file name, refresh the PowerQuery and run the macro.
My code so far is a simple copy paste of the folders but I'd like to insert functions to have:
import shutil
original = r"C:\Users\name\Desktop\9.13.2021 - Daily Item Record.xlsm"
target = r"C:\Users\name\Desktop\9.14.2021 - Daily Item Record.xlsm"
shutil.copyfile(original, target)
The above involves changing the dates every day. Instead, I'd like to have the original
file path be the most recent file in the directory and the target
file be the copy with today's date.