Jump to content

File copied to clip as file


Recommended Posts

How can I put one simple file in clipboard so I can use it later?

I did try few times but dont know where I am wrong...

File is in same dir where script is...

Those lines blow doesn't make sense since I did try few times and it wouldnt work... so its all mixed up...

It should be just 2 lines... but dont know how to write it right...

;$file = FileOpen("file.txt", 0)
;$clip = FileRead($file, 1)
FileCopy("file.txt", $file)
ClipPut($file,1)
;ClipPut($clip)
;$file = "file.txt"
;ClipPut("file.txt")
Link to comment
Share on other sites

For half an hour I did try to understand what is all about in that link but I cant understand "_CreateDROPFILES" and "_CreatePREFERREDDROPEFFECT($DROPEFFECT_COPY)"...

I can guess that many would tell me "leave the autoit and go play with the ball" but I am too fat for 1 ball...

Anyway... There is no simple command which would get one file in clipboard? I just need to get it in clipboard.

I would manualy press "ctrl + v" in explorer and paste that file somewhere I have a need for...

I only need the way how can I get one file in clipboard, like if there would be a command like:

FileCopy("file.txt", $file)
Clipput($file)

Something like that? It should be just few lines...

Can You or any other guy in here give me simple 2 line example how can I put a file "file.txt" which is in same dir as script in clipboard?

PS: I think that your FF plugin is great and many other stuff which You wrote and I could not understand at the moment (or many other moments in the future). Anyway I hope You guys support people who likes autoit and they are not programmers or script coders, or... that clever. Thats why I ask for simple things... At least I hope they must be simple because I dont get it and it should be just few lines. Thanks in advance!

Link to comment
Share on other sites

  • Moderators

ClipPut(FileRead($file))

?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

There is a function called _ClipPutFile which should do the trick. It's in the help file.

Lol, never saw that one :idea:. But the above one also allows you not only to copy to clipboard but also to cut (move) files... wrapped it a little bit...

#include<Memory.au3>
#include<ClipBoard.au3>


$sFiles = @ScriptDir & "\test1.txt" & "|" & @ScriptDir & "\test2.txt"
_ClipPutFileEx($sFiles, 2)



Func _ClipPutFileEx($sFiles = "", $iOpType = 1)
    ; $sFiles, list of files, separated by "|"
    ; $iOpType: 1 = Copy, 2 = Move (Cut)

    Local Const $DROPFILES = "DWORD pFiles; int pt[2]; int fNC; int fWide;"

    Local Const $CFSTR_PREFERREDDROPEFFECT = "Preferred DropEffect"
    Local Const $CF_PREFERREDDROPEFFECT = _ClipBoard_RegisterFormat($CFSTR_PREFERREDDROPEFFECT)

    Local Const $DROPEFFECT_NONE = 0
    Local Const $DROPEFFECT_COPY = 1
    Local Const $DROPEFFECT_MOVE = 2
    Local Const $DROPEFFECT_LINK = 4
    Local Const $DROPEFFECT_SCROLL = 0x80000000

    Local $hClip = _ClipBoard_Open(WinGetHandle("Program Manager"))
    _ClipBoard_Empty()

    $HDROP = _CreateDROPFILES($sFiles,$DROPFILES)

    Local $DROPEFFECT
    Switch $iOpType
        Case 2
            $DROPEFFECT = _CreatePREFERREDDROPEFFECT($DROPEFFECT_MOVE)
        case Else
            $DROPEFFECT = _CreatePREFERREDDROPEFFECT($DROPEFFECT_COPY)
    EndSwitch

    _ClipBoard_SetDataEx($HDROP, $CF_HDROP)
    _ClipBoard_SetDataEx($DROPEFFECT, $CF_PREFERREDDROPEFFECT)
    _ClipBoard_Close()

EndFunc   ;==>_ClipPutFileEx

; ProgAndy
; http://www.autoitscript.com/forum/index.php?showtopic=91046&view=findpost&p=654849
; http://www.autoit.de/index.php?page=Thread&postID=81909&highlight=hdrop#post81909

;===============================================================================
;
; Function Name:   _CreateDROPFILES
; Description::    Creates a DROPFILES-structure
; Parameter(s):    $Files - Pipe-separated list of files to copy: example: C:\File1.bin|D:\AnotherFile.dat
; Requirement(s):  COM/OLE UDF
; Return Value(s): HGLOBAL-Pointer to a DROPFILES structure
; Author(s):       prog@ndy
;
;===============================================================================
;
Func _CreateDROPFILES($Files,$DROPFILES)
    $Files = String($Files)

    $hMem = _MemGlobalAlloc(_DragDrop_SIZEOF($DROPFILES) + ((StringLen($Files) + 2) * 2), $GPTR)
    $Files = StringSplit($Files, "|")
    $stDROPFILES = DllStructCreate($DROPFILES, $hMem)
    $hPtr = $hMem + DllStructGetSize($stDROPFILES)
    DllStructSetData($stDROPFILES, "fWide", 1)
    DllStructSetData($stDROPFILES, 1, DllStructGetSize($stDROPFILES))
    For $i = 1 To $Files[0]
        $next = DllStructCreate("wchar[" & StringLen($Files[$i]) + 1 & "]", $hPtr)
        DllStructSetData($next, 1, $Files[$i] & ChrW(0))
        $hPtr += (StringLen($Files[$i]) + 1) * 2
    Next
    $next = DllStructCreate("wchar[1]", $hPtr)
    DllStructSetData($next, 1, ChrW(0))
    Return $hMem
EndFunc   ;==>_CreateDROPFILES

; Prog@ndy
Func _CreatePREFERREDDROPEFFECT($dwEffect)
    Local $pMem = _MemGlobalAlloc(4, $GPTR) ; 4 bytes - 1 DWORD
    If Not $pMem Then Return SetError(1, 0, 0)
    DllStructSetData(DllStructCreate("DWORD", $pMem), 1, $dwEffect)
    Return $pMem
EndFunc   ;==>_CreatePREFERREDDROPEFFECT

; Author: Prog@ndy
Func _DragDrop_SIZEOF($tagStruct)
    Return DllStructGetSize(DllStructCreate($tagStruct, 1))
EndFunc   ;==>_DragDrop_SIZEOF
Link to comment
Share on other sites

Lol, never saw that one :). But the above one also allows you not only to copy to clipboard but also to cut (move) files... wrapped it a little bit...

It will take me a bit of time to figure this one out. Thanks for posting however: it is interesting. Although it's not the same thing, it reminds me of one time when I started to write a certain bitwise function before I realized that it had a name and already existed. :idea:
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...