I want to copy a file to the clipboard. So if the user of my program goes into a directory or want to send the file attached in an email, they can just paste the file into the directory or email.

I understand how to copy the file to another directory but that is not necessarily what I want here. I want it so the user can paste the document wherever they choose.

Thanks for any suggestions!

I want to copy a file to the clipboard. So if the user of my program goes into a directory or want to send the file attached in an email, they can just paste the file into the directory or email.

I understand how to copy the file to another directory but that is not necessarily what I want here. I want it so the user can paste the document wherever they choose.

Thanks for any suggestions!

Could you explain why do you need this? Every OS as far as I know has already implemented. Usually, the path of the file is copied, and when the user chooses to 'paste' his file, the OS understands the special meaning of the keyboard contents and the necessary operations are taken.
You could try to implement something similar..?

I would like to use this mainly for attaching files to emails. My program links tree items to files on a user's computer. This is a way to better organize a user's files. Instead of browsing to each file (which is a lot of clicking). I save the file links by saving the filepaths in a database.

The current way to quickly attach a file to an email is to browse for it. I simply want to eliminate that browsing for the user especially because I already know the filepath of the file they want to attach.

So, going by what you are saying, perhaps if I simply save the filepath to the clipboard, then paste that filepath in the email attachment, Windows will know what to do and will paste the file and not just the filepath.

I will give that a try and let you know.

Thank you and if you think of anything else please let me know.

In linux (and especially in KDE), the path that is copied is file:///home/myle/Desktop/tmp/dani/copy.py for instance. If you select multiple files, a list is created. That's the special form of the links.

I don't know how Windows handle it, but I guess a similar approach is highly probable; I don't think that they copy entire files in the clipboard.
When you solve your problem, if you are able, attach the code which interacts with the clipboard.

I am using the clipbrd.exe in Windows/System32 to look at the clipboard. I am finding some very interesting things.

I have a pdf file whose directory path is "C:\Users\owner\Desktop\Folder"

If I name the pdf "pdfFile", what shows up on the clipboard is the filepath exactly.

However, if the name of the pdf gets to 9 characters or more, it does not save the filepath exactly. So by changing the name of the pdf to "pdfFileab.pdf" the clipboard contents look something like this.

"C:\Users\owner\Desktop\Folder\PDFFIL~1.PDF"

Please note that the tilda (~) is not exactly how it appears here. It appears to be superscripted on the clipboard. Also, the clipboard does not change if I changed the name to pdfFileabcd or any thing more than pdfFileab.

Now, if I created another pdf called pdfFile12 or pdfFileabcd. Then the clipboard contents become:

"C:\Users\owner\Desktop\Folder\PDFFIL~2.PDF"

So here is my conclusion. If the name of the file you are copying is shorter than 9 characters and has no spaces, the clipboard seems to copy the filepath exactly. If the name of the file is 9 characters or longer with no spaces, the clipboard capitalizes the first 6 characters of the filename adds a superscripted tilda and keeps track of how many other files are named with the same first 6 characters in the folder.

If there is a space in the filename, no matter the length of the name, clipboard gets rid of the spaces, capitalizes the first 6 characters (or less if the name is shorter than 6 characters) adds the superscripted tilda and puts a number on the end before the file extension representing how many files are named similarly.

The way you say Linux does this sounds much simpler...not surprising...

I think that if I want to copy a file using python...I have to somehow make windows copy it or something...or just chalk this up under Windows is a pain sometimes.

Any further suggestions would be appreciated. Thank you.

In ancient years, dos was supporting filenames with (at most) 8 characters. So, I guess what you get is the dos name of the file. If you use that instead of the actual name, you should be fine (my best guess since I don't use anymore Windows).

Comments
Very helpful.

Windows is using the dos, or short, name to copy files to the clipboard. I was able to get the short name of files and put it to the clipboard in python. However, it still did not work. Windows is doing something else that I do not know.

Regardless, thank you very much for the help myle.

Edited 7 Years Ago by jcmeyer: n/a

This article has been dead for over six months. Start a new discussion instead.