copy a specific file by name

Asked by Rahul Kumar on 2017-03-05

I want to open a folder, highlight a specific image file by its name, and then:
1. copy the file on clipboard, so that later I can paste {type("v", KEY_CTRL)} into oneNote
2. doubelClick so that it opens up in a third party windows application

Listing files and getting their names is easy through python, but shutil.copy needs destination directory. In my case I want to paste that file content into oneNote(already opened, shall not open again and again). Even if the file (not only name) could be copied to clipboard programmatically, there is a problem of this third party app. which on pressing CTRL+N, opens file explorer, where when user double clicks a file, it gets opened in that app.

Please suggest a solution.

Question information

Language:
English Edit question
Status:
Expired
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-03-07
Last reply:
2017-03-23

This question was reopened

RaiMan (raimund-hocke) said : #1

- read content of file to a String (Python)
- use paste() to insert the content where needed
- then click as needed

Nothing really complex.

Rahul Kumar (rahulkumar) said : #2

"...I want to paste that file content into oneNote.."- Maybe this part is not clear enough. I want to copy the image as such in oneNote, rather than read the content of the image (probably binary data) and paste it in onenote

Rahul Kumar (rahulkumar) said : #3

Raiman, maybe you are right.

I solved my problem this way (copied code from somewhere else):

ABC.py
===========
from cStringIO import StringIO
import win32clipboard
import sys
from PIL import Image

def send_to_clipboard(clip_type, data):
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardData(clip_type, data)
    win32clipboard.CloseClipboard()

print("-----"+sys.argv[1])
image = Image.open(sys.argv[1])

output = StringIO()
image.convert("RGB").save(output, "BMP")
data = output.getvalue()[14:]
output.close()

send_to_clipboard(win32clipboard.CF_DIB, data)

from sikuli
===============
os.system("python <path to ABC.py> " + <filepath>)

This ABC.py had to be made separate, as sikuli does not support win32clipboard

Rahul Kumar (rahulkumar) said : #4

However converting from RGB into BMP has reduced the image quality drastically

Launchpad Janitor (janitor) said : #5

This question was expired because it remained in the 'Open' state without activity for the last 15 days.