I'm using Pyautogui to take a screenshot of a portion of the screen, below is a snippet of the code - the code works fine but the created file just seems to be created in the same directory as the python file. When given a path name it takes part of it and makes it into its name.
The code:
def takeBoundedScreenShot(self, x1, y1, x2, y2):
im = pyautogui.screenshot(region=(x1, y1, x2, y2))
x = datetime.datetime.now()
fileName = x.strftime("%f")
im.save(r'C:\Users\user\PycharmProjects\PDFCapture\output_folder_one' + fileName + ".png")
with this file path the created file is stored in the same folder as the python project but with the file name 'output_folder_one' + 'fileName'
I have a folder in this directory called output_folder_one - I am not sure why the created files are not being stored in there.
Any insight would be greatly appreciated!! :
I believe that behaviour is due to the way your path is set.
im.save(r'C:\Users\user\PycharmProjects\PDFCapture\output_folder_one' + fileName + ".png")
If you see the line above the filename will be taken as output_folder_one' + fileName + ".png"
and hence will be saved in the directory where your python project is based. So try adding a \
to separate the output_folder_one
and the following suffix filename. It should be
im.save(r'C:\Users\user\PycharmProjects\PDFCapture\output_folder_one\' + fileName + ".png")