I tried to output my file to the specified path with the file name created with current date and time so I first used timestr to store the current date and time:
import time
timestr = time.strftime("%Y%m%d-%H%M%S")
The output directory is defined as below:
FolderLocation = r'C:\Users\Desktop\Tool'
Results= FolderLocation + "\Results -" + timestr + ".xlsx"
with pd.ExcelWriter(Results, engine='openpyxl', mode='a') as writer:
IR.to_excel(writer, sheet_name='Inputs',startrow=0, index=False)
However, when running the program, the single-backslashes in my specified output directory are changed to double-backslashes and results in the below error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Desktop\\Tool\\Results -20210516-143255.xlsx'
As I would like to save the output files with file name of current date and time, I cannot give the name of a file which actually exists. Does anyone have an idea how to solve this? Many thanks!