I created a pdf and a folder. The pdf is inside this folder. When re_running the code this is supposed to check if this folder exists and then if so, remove it and create it again (replacing it). If the folder does not exist then just create it normally. I am running into a permission error
. I am wondering wow I can achieve this.
See code below:
newpath = rf'C:\Users\{username}\Desktop\Output Folder(MC)-{jobnumber}'
if os.path.exists(newpath):
os.remove(newpath)
os.makedirs(newpath)
else:
os.makedirs(newpath)
The full error is:
os.remove(newpath) PermissionError: [WinError 5] Access is denied: 'C:\\Users\\rherencia\\Desktop\\Output Folder(MC)-ITI-034214-1-1'