I have a script which outputs an excel file '.xlsx' containing various data. It generates a file with the date in the name in one folder, and then generates a copy, using shutil.copy(), in a separate folder. I then rename the file using os.rename(), however instead of overwriting the file already there, it produces the following error:
"FileExistsError: [WinError 183] Cannot create a file when that file already exists:"

I need the file to be exactly the same name everytime the script is run, as it is subsequently used as an automatic input file for PowerBI.
Current code is as follows:
# Select file you want to copy & where to copy it to
src_file = vb.output_path
destination = vb.path_reports_cashflowcopy

# Copy the file
shutil.copy(src_file, destination)

# Define copy path
cashflow_copy_path = vb.ROOT_DIR + '\\Data_and_Reports\\Reports\\Cashflow Copies\\'

# Rename the file
os.rename(cashflow_copy_path + str(date.today()) + ' -  Lettings Report BETA - '  +       vb.academic_year_selection +  '.xlsx',
          cashflow_copy_path + 'Copy ' + vb.academic_year_selection + '.xlsx')

src_file is the original output excel file created.
vb.xxxxxx is from a connected script which describes various file paths and other inputs used to name the files.

How can I overwrite a file in a different folder using shutil.copy() and os.rename() in Python?
To avoid the "FileExistsError" when renaming the file, you can check if the destination file already exists before renaming it.
import os
import shutil
from datetime import date

# Select file you want to copy & where to copy it to
src_file = vb.output_path
destination = vb.path_reports_cashflowcopy

# Copy the file
shutil.copy(src_file, destination)

# Define copy path
cashflow_copy_path = vb.ROOT_DIR + '\\Data_and_Reports\\Reports\\Cashflow Copies\\'

# Rename the file
new_file_name = cashflow_copy_path + 'Copy ' + vb.academic_year_selection + '.xlsx'
existing_file = cashflow_copy_path + str(date.today()) + ' -  Lettings Report BETA - ' + vb.academic_year_selection + '.xlsx'

if os.path.exists(existing_file):
    os.remove(existing_file) # Delete the existing file if it exists

os.rename(src_file, new_file_name)

