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

Get help with using AutoHotkey and its commands and hotkeys
cadudesun
Posts: 66
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: 10
Joined: 09 Dec 2018, 22:28
Location: Hungary
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.
cadudesun
Posts: 66
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")
}

Return to “Ask For Help”

Who is online

Users browsing this forum: boton, Google [Bot], tenkeylessph and 204 guests