I have spent the last 4 hours trying to solve this problem. I am downloading images from a website and storing them in Users/Temp. What I want to do is, when downloading an image, check the temp folder to see if there are any already there with the same name. If there are, then rename them using an f string and a counter, but still download and save them.
for bmp in bmp_list:
fullfilename = os.path.join(f'{dl_location}', f'{bmp}')
dl_link = url + bmp
urllib.request.urlretrieve(dl_link, fullfilename)
if os.path.isfile(fullfilename):
print('file already exists, renaming.')
os.rename(fullfilename, f'copy{c}-{fullfilename}')
c =+1
else: None
I know that my code is creating the file, then checking if it is there and obviously it is there because I just copied it, but I am quite stuck. Help would be greatly appreciated!
EDIT: when i run this code I get the error message
FileNotFoundError: [Errno 2] No such file or directory: '/Users/Home/Temp/CW/monty-python-(1).bmp' -> 'copy1-/Users/Home/Temp/CW/monty-python-(1).bmp'