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

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:

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):
from cStringIO import StringIO
import win32clipboard
import sys
from PIL import Image

def send_to_clipboard(clip_type, data):
    win32clipboard.SetClipboardData(clip_type, data)

image =[1])

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

send_to_clipboard(win32clipboard.CF_DIB, data)

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

This 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.