Copying Screenshots using Python

Asked by Viral Bhatt

As we know, it is not possible to name the screenshots and change the output directory but can we copy the image files and paste it somewhere using some Python API's? I tried using shutil but it does not work out as it gives error. Any thoughts??

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

shutil.move(from, to) should work.

The to-directory must exist and you must have full write permission (e.g. a folder in c:\Program Files does not work, because it is access protected).

Revision history for this message
Viral Bhatt (virubhatt7) said :
#2

I tried doing shutil.move and shutil.copyfile but i get an error
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\shutil.py", line 52, in copyfile
 IOError: (13, 'EACCES', to-directory)
I know it is an access issue, I have provided all the permissions to this folder. Any thoughts??

Thanks,
Viral Bhatt

Revision history for this message
RaiMan (raimund-hocke) said :
#3

If you get this error, the access rights are definitely not ok.

try to copy the file by hand and see what happens.

Revision history for this message
Viral Bhatt (virubhatt7) said :
#4

I tried copy/paste by hand and it works fine.. Not sure what is the issue?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

pls. paste the relevant code.

Revision history for this message
Viral Bhatt (virubhatt7) said :
#6

f=capture(region)
shutil.move(f,"C:\Documents and Settings\User\Desktop")

Revision history for this message
RaiMan (raimund-hocke) said :
#7

--- "User" must be the name of the currently logged in user.

--- The second parameter wants a filename, so

shutil.move(f,"C:\Documents and Settings\User\Desktop\some-name.png")

works

Revision history for this message
Viral Bhatt (virubhatt7) said :
#8

Hi,

I tried doing what you said it works but it requires two '\\' marks before the User........i.e
C:\Documents and Settings\\vbhatt\Desktop\somefilename.png.............but the name which is returned by capture() method has only 1 '\' mark. Let me know if u can find any work around this.....

Revision history for this message
RaiMan (raimund-hocke) said :
#9

Sorry, for being faulty :-(

In a filename string back slashes must either be escaped (doubled) or you may use a raw string r"some text that is taken as is".

shutil.move(f,r"C:\Documents and Settings\ vbhatt\Desktop\some-name.png")

Can you help with this problem?

Provide an answer of your own, or ask Viral Bhatt for more information if necessary.

To post a message you must log in.