How to copy the FULL file to clipboard from specific path?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cadudesun
Posts: 129
Joined: 04 Jun 2016, 10:26

How to copy the FULL file to clipboard from specific path?

26 Apr 2019, 08:44

Hello,

I'd appreciate your help.

I have some template files stored in specific paths, for instance:
C:\TEMPLATES\File.pdf
C:\TEMPLATES\File.docx
C:\TEMPLATES\File.png

Does anyone know a script to copy the FULL file (e.g. "File.docx") from the path (C:\TEMPLATES\File.docx) to the clipboard?

By FULL file I mean the file itself, and not the path, or the internal content.
So if I run this script, and then paste (ctrl+v) in file explorer, "File.docx" should be pasted.
The intention of the script is to create shortcuts to my main template files, for easy access and usage.

Thank you very much!
User avatar
aeiklmr
Posts: 17
Joined: 09 Dec 2018, 22:28
Location: Europe
Contact:

Re: How to copy the FULL file to clipboard from specific path?

26 Apr 2019, 10:26

Lexikos has written some wonderful posts related to your issue.

https://autohotkey.com/board/topic/23162-how-to-copy-a-file-to-the-clipboard/page-1

I think this is what you're looking for sir.
I like to think extroverts have attention dependency disorder.

my projects: D2 Reconsidered - Diablo 2 Resurrected script | HideMyIcon, customizable desktop icon hider for Windows 10
cadudesun
Posts: 129
Joined: 04 Jun 2016, 10:26

Re: How to copy the FULL file to clipboard from specific path?

27 Apr 2019, 13:40

aeiklmr wrote:
26 Apr 2019, 10:26
Lexikos has written some wonderful posts related to your issue.

https://autohotkey.com/board/topic/23162-how-to-copy-a-file-to-the-clipboard/page-1

I think this is what you're looking for sir.
Many thanks for the topic direction.
I'm trying to use the syntaxes available at the end of the topic without success:
https://autohotkey.com/board/topic/23162-how-to-copy-a-file-to-the-clipboard/page-4

Also, I'm wondering if I so complex syntax is needed to just copy a file from a specified path.

Does anyone have further information on how to copy a file from a specified path?
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to copy the FULL file to clipboard from specific path?

27 Apr 2019, 16:29

Lexikos' FileToClipboard function at the link that aeiklmr gave works for me. I ran it in a folder with a 1GB movie file, right-clicked on my desktop, clicked Paste and the movie file was copied to my desktop. Is that not what you're after?

Code: Select all

FileToClipboard("test.mkv")

FileToClipboard(PathToCopy)
{
    ; Expand to full paths:
    Loop, Parse, PathToCopy, `n, `r
        Loop, %A_LoopField%, 1
            temp_list .= A_LoopFileLongPath "`n"
    PathToCopy := SubStr(temp_list, 1, -1)
    
    ; Allocate some movable memory to put on the clipboard.
    ; This will hold a DROPFILES struct and a null-terminated list of
    ; null-terminated strings.
    ; 0x42 = GMEM_MOVEABLE(0x2) | GMEM_ZEROINIT(0x40)
    hPath := DllCall("GlobalAlloc","uint",0x42,"uint",StrLen(PathToCopy)+22)
    
    ; Lock the moveable memory, retrieving a pointer to it.
    pPath := DllCall("GlobalLock","uint",hPath)
    
    NumPut(20, pPath+0) ; DROPFILES.pFiles = offset of file list
    
    pPath += 20
    ; Copy the list of files into moveable memory.
    Loop, Parse, PathToCopy, `n, `r
    {
        DllCall("lstrcpy","uint",pPath+0,"str",A_LoopField)
        pPath += StrLen(A_LoopField)+1
    }
    
    ; Unlock the moveable memory.
    DllCall("GlobalUnlock","uint",hPath)
    
    DllCall("OpenClipboard","uint",0)
    ; Empty the clipboard, otherwise SetClipboardData may fail.
    DllCall("EmptyClipboard")
    ; Place the data on the clipboard. CF_HDROP=0xF
    DllCall("SetClipboardData","uint",0xF,"uint",hPath)
    DllCall("CloseClipboard")
}
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How to copy the FULL file to clipboard from specific path?

11 Nov 2022, 17:54

Hello,

sorry for the "grave shoveling", but I tried it and it did not work.
Apparantly there is something inside of the Clipboard (after I run the script), but when I want to paste it, there is just this Windows error sound when you press keys but nothing happens...

My file is for example this:
C:\song.mp3

When I'm on any folder (e.g. on D:\Music\) I would like to paste it.

Maybe Lexikos' FileToClipboard function has to be written different for Windows 10?

The scriptDir and the files are not in the same location (in my case)

Thanks for any help and best regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: How to copy the FULL file to clipboard from specific path?

11 Nov 2022, 17:59

I've had good success with just me's ClipboardSetFiles() viewtopic.php?p=63914#p63914
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: How to copy the FULL file to clipboard from specific path?

12 Nov 2022, 18:27

Thank you - this works!

I made it a little bit smaller, because I don't need the part with the sorting.

So it's just:
F1::
ClipBoardSetFiles("C:\Song.mp3")
return


The function is the same, but at the end I added a ClipWait, 0.3 and Send ^v

I did several tests and everything was fine. :bravo:

Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
joexcm
Posts: 7
Joined: 24 Jan 2023, 14:25

Re: How to copy the FULL file to clipboard from specific path?

24 Jan 2023, 14:27

Hi Scr1pter, could you post your code please?
I'm really struggling with various copy-paste codes and wouldn't even know where to start amending someone else's script. Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], rc76, uchihito and 388 guests