Bop Posted March 18, 2012 Share Posted March 18, 2012 I can copy a file or folder to the clipboard with _ClipPutFile(). Now how do I paste it from the clipboard to a specific folder? (From an AutoIt script, of course.) I want something a little more elegant than shellexecute windows explorer and send keys "^v", closewindow... Link to comment Share on other sites More sharing options...
Rogue5099 Posted March 18, 2012 Share Posted March 18, 2012 Try using DirCopy or FileCopy. My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Bop Posted March 19, 2012 Author Share Posted March 19, 2012 (edited) I cannot use filecopy or Dircopy because the source may come from copying to the clipboard from Wndows Explorer or from _ClipPutFile(). Also, is it posible to cut to the clipboard, so that when I paste from the clipboard, the original will be deleted? Edited March 19, 2012 by Bop Link to comment Share on other sites More sharing options...
Rogue5099 Posted March 19, 2012 Share Posted March 19, 2012 The only way to paste the file would be to have a destination directory. In which case a "cut" would be the same as FileMove. You can use _ClipPutFile() to get the original path and FileMove(ClipGet(), "dest") My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Bop Posted March 27, 2012 Author Share Posted March 27, 2012 Great. Just what I wanted. Thank you very much. Is there any way to programatically determine if the file or folder was "Cut" or "Copied" to the clipboard? (for when I "Cut" or "Copy" from Windows Explorer.) Also, can I set the "Cut" or "Copied" state of the clipboard to make the entire thing seamless? Link to comment Share on other sites More sharing options...
Rogue5099 Posted March 28, 2012 Share Posted March 28, 2012 (edited) Getting the information of what the clipboard has on it is just that. It doesn't say how the data is there it just says what data is there. Cut in Explorer just tells the OS to move the file once pasted. It is not actually storing the data to the clipboard like cut/copy text within notepad for example. Copy is the same way. Windows Explorer is best used with 2 open windows and you just click and drag from/to new location "cut". If you are using the cut/copy it is the same as using Command Lines.CLIP Copy STDIN to the Windows clipboard.Standard input (stdin) is data (often text).COPY Copy one or more files to another location•MOVE Move files from one folder to another•As you see there is no command line for "cut".ROBOCOPY was added to Windows 7 that was an advanced utility to copy files and directory trees.Also, can I set the "Cut" or "Copied" state of the clipboard to make the entire thing seamless?I don't understand this part unless you are asking to get info telling you that the data on the clipboard is either copied or cut? The answer to that is no. (to my knowledge) Edited March 28, 2012 by rogue5099 My projects: Inventory / Mp3 Inventory, Computer Stats Link to comment Share on other sites More sharing options...
Bop Posted April 6, 2012 Author Share Posted April 6, 2012 (edited) I finally figured out how to do both. A pox on MS documentation standards. If anyone finds this usefull or finds any bugs; I would appreciate hearing about it. (BOP) ; #FUNCTION# ==================================================================================================================== ; Name...........: _ClipCopyCutFile ; Description ...: Copy or Cut Files to Clipboard (almost) Like Explorer does ; Syntax.........: _ClipCopyCutFile($sFile[,$DROPEFFECT=5[, $sSeparator = "|"]]) ; Parameters ....: $sFile - Full Path to File(s) ; $DROPEFFECT - 5=Copy(default), 2=Cut ; $sSeparator - Seperator for multiple Files, Default = '|' ; Return values .: Success - True ; Failure - False and Sets @ERROR to: ; |1 - Unable to Open Clipboard ; |2 - Unable to Empty Cipboard ; |3 - GlobalAlloc Failed ; |4 - GlobalLock Failed ; |5 - Unable to Create DLLStruct ; |6 - Unable to Update Clipboard ; |7 - Unable to Close Clipboard ; |8 - GlobalUnlock Failed ; |9 - GlobalFree handle Failed ; |10- Invalid $DROPEFFECT ; Author ........: Piccaso (Florian Fida) ; Modified.......: Gary Frost (gafrost) ; Modified.......: JCCW (BOP) ; Remarks .......: This routine only puts "HDrop" and "Prefered DropEffect" clipboard formats ; on the clipboard. ; Windows Explorer also puts: ; -DataObject ; -Shell IDList Array ; -FileName ; -FileNameW ; -Ole Private Data ; It seems to work though. ; Related .......: ; Link ..........: ; Example .......: no ; =============================================================================================================================== Func _ClipCopyCutFile($sFile, $DROPEFFECT=5, $sSeparator = "|") Local Const $GMEM_MOVEABLE = 0x0002, $CF_HDROP = 15 $sFile &= $sSeparator & $sSeparator Local $nGlobMemSize = 2 * (StringLen($sFile) + 20) Local $PreferredDropEffect = _ClipBoard_RegisterFormat("Preferred DropEffect") ; $DROPEFFECT 2= cut, 5= copy If $DROPEFFECT <> 2 And $DROPEFFECT <> 5 Then Return SetError(10,10,False) Local $aResult = DllCall("user32.dll", "bool", "OpenClipboard", "hwnd", 0) If @error Or $aResult[0] = 0 Then Return SetError(1, _WinAPI_GetLastError(), False) Local $iError = 0, $iLastError = 0 $aResult = DllCall("user32.dll", "bool", "EmptyClipboard") If @error Or Not $aResult[0] Then Return _CCCFError(2,_WinAPI_GetLastError()) $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", $nGlobMemSize) If @error Or Not $aResult[0] Then Return _CCCFError(3,_WinAPI_GetLastError()) Local $hGlobal = $aResult[0] Local $aResult1 = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", 52) ;Note: 52 is an arbitrary number. I know it is at least 4 bytes and 52 should be big enough. ;A pox on MS documentation standards. If @error Or Not $aResult1[0] Then Return _CCCFError(3,_WinAPI_GetLastError()) Local $hGlobal1 = $aResult1[0] $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hGlobal) If @error Or Not $aResult[0] Then Return _CCCFError(4,_WinAPI_GetLastError()) Local $hLock = $aResult[0] $aResult1 = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hGlobal1) If @error Or Not $aResult1[0] Then Return _CCCFError(4,_WinAPI_GetLastError()) Local $hLock1 = $aResult1[0] Local $DROPFILES = DllStructCreate("dword pFiles;" & $tagPOINT & ";bool fNC;bool fWide;wchar[" & StringLen($sFile) + 1 & "]", $hLock) If @error Then Return SetError(5, 6, False) Local $DROPFILES1 = DllStructCreate("dword CFSTR_PREFERREDDROPEFFECT", $hLock1) If @error Then Return SetError(5, 6, False) Local $tempStruct = DllStructCreate("dword;long;long;bool;bool") DllStructSetData($DROPFILES, "pFiles", DllStructGetSize($tempStruct)) DllStructSetData($DROPFILES, "X", 0) DllStructSetData($DROPFILES, "Y", 0) DllStructSetData($DROPFILES, "fNC", 0) DllStructSetData($DROPFILES, "fWide", 1) DllStructSetData($DROPFILES, 6, $sFile) For $i = 1 To StringLen($sFile) If DllStructGetData($DROPFILES, 6, $i) = $sSeparator Then DllStructSetData($DROPFILES, 6, Chr(0), $i) Next $aResult = DllCall("user32.dll", "handle", "SetClipboardData", "uint", $CF_HDROP, "handle", $hGlobal) If @error Or Not $aResult[0] Then $iError = 6 $iLastError = _WinAPI_GetLastError() EndIf DllStructSetData($DROPFILES1, "CFSTR_PREFERREDDROPEFFECT", $DROPEFFECT) $aResult1 = DllCall("user32.dll", "handle", "SetClipboardData", "uint", $PreferredDropEffect, "handle", $hGlobal1) If @error Or Not $aResult1[0] Then $iError = 6 $iLastError = _WinAPI_GetLastError() EndIf $aResult = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hGlobal) If (@error Or Not $aResult[0]) And Not $iError And _WinAPI_GetLastError() Then $iError = 8 $iLastError = _WinAPI_GetLastError() EndIf $aResult1 = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hGlobal1) If (@error Or Not $aResult1[0]) And Not $iError And _WinAPI_GetLastError() Then $iError = 8 $iLastError = _WinAPI_GetLastError() EndIf $aResult = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hGlobal) If (@error Or $aResult[0]) And Not $iError Then $iError = 9 $iLastError = _WinAPI_GetLastError() EndIf $aResult1 = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hGlobal1) If (@error Or $aResult1[0]) And Not $iError Then $iError = 9 $iLastError = _WinAPI_GetLastError() EndIf Return _CCCFError($iError,$iLastError) EndFunc ;==>_ClipCopyCutFile Func _CCCFError($error=0,$extended=0) Local $aResult = DllCall("user32.dll", "bool", "CloseClipboard") If (@error Or Not $aResult[0]) And Not $error Then Return SetError(7, _WinAPI_GetLastError(), False) If $error Then Return SetError($error, $extended, False) Return True EndFunc;_CCCFError Func _ClipBoardContents() ; Returns 0 if clipboard is empty or does not contain ; clipboard format "HDrop". ; Returns 2 if clipboard contains cut file(s) ;(ClipBoard Format:"Preferred DropEffect" = 2 and ClipBoard Format:"HDrop"). ; Returns 5 if clipboard contains copied file(s) (ClipBoard Format:"HDrop"). ; Sets @error if clipboard does not contain at least one file (one ClipBoard Format:"HDrop"). Local $CBF = 0,$CBFS,$data,$CountDropEffect2 = 0,$CountHDrop=0 Do Local $CBO = _ClipBoard_Open(0) $CBF = _ClipBoard_EnumFormats($CBF) If $CBF = 0 Then ExitLoop $CBFS = _ClipBoard_FormatStr($CBF) If $CBFS = "Preferred DropEffect" Then $data = BinaryMid(_ClipBoard_GetData($CBF),1,4) If $data = 2 Then $CountDropEffect2 +=1 EndIf If $CBFS = "HDrop" Then $CountHDrop +=1 Until Not $CBF _ClipBoard_Close() If $CountHDrop <> 1 Then Return SetError(1,1,0) If $CountDropEffect2 = 1 Then Return SetError(0,0,2) Return SetError(0,0,5) EndFunc Edited April 6, 2012 by Bop Link to comment Share on other sites More sharing options...
Bop Posted April 16, 2012 Author Share Posted April 16, 2012 (edited) This is a cleaner copy with the formating and the #Include expandcollapse popup#include <Clipboard.au3> ; #FUNCTION# ==================================================================================================================== ; Name...........: _ClipCopyCutFile ; Description ...: Copy or Cut Files to Clipboard (almost) Like Explorer does ; Syntax.........: _ClipCopyCutFile($sFile[,$DROPEFFECT=5[, $sSeparator = "|"]]) ; Parameters ....: $sFile - Full Path to File(s) ; $DROPEFFECT - 5=Copy(default), 2=Cut ; $sSeparator - Seperator for multiple Files, Default = '|' ; Return values .: Success - True ; Failure - False and Sets @ERROR to: ; |1 - Unable to Open Clipboard ; |2 - Unable to Empty Cipboard ; |3 - GlobalAlloc Failed ; |4 - GlobalLock Failed ; |5 - Unable to Create DLLStruct ; |6 - Unable to Update Clipboard ; |7 - Unable to Close Clipboard ; |8 - GlobalUnlock Failed ; |9 - GlobalFree handle Failed ; |10- Invalid $DROPEFFECT ; Author ........: Piccaso (Florian Fida) ; Modified.......: Gary Frost (gafrost) ; Modified.......: JCCW (BOP) ; Remarks .......: This routine only puts "HDrop" and "Prefered DropEffect" clipboard formats ; on the clipboard. ; Windows Explorer also puts: ; -DataObject ; -Shell IDList Array ; -FileName ; -FileNameW ; -Ole Private Data ; It seems to work though. ; Related .......: ; Link ..........: ; Example .......: no ; =============================================================================================================================== Func _ClipCopyCutFile($sFile, $DROPEFFECT=5, $sSeparator = "|") Local Const $GMEM_MOVEABLE = 0x0002, $CF_HDROP = 15 $sFile &= $sSeparator & $sSeparator Local $nGlobMemSize = 2 * (StringLen($sFile) + 20) Local $PreferredDropEffect = _ClipBoard_RegisterFormat("Preferred DropEffect") ; $DROPEFFECT 2= cut, 5= copy If $DROPEFFECT <> 2 And $DROPEFFECT <> 5 Then Return SetError(10,10,False) Local $aResult = DllCall("user32.dll", "bool", "OpenClipboard", "hwnd", 0) If @error Or $aResult[0] = 0 Then Return SetError(1, _WinAPI_GetLastError(), False) Local $iError = 0, $iLastError = 0 $aResult = DllCall("user32.dll", "bool", "EmptyClipboard") If @error Or Not $aResult[0] Then Return _CCCFError(2,_WinAPI_GetLastError()) $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", $nGlobMemSize) If @error Or Not $aResult[0] Then Return _CCCFError(3,_WinAPI_GetLastError()) Local $hGlobal = $aResult[0] Local $aResult1 = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", 52) ;Note: 52 is an arbitrary number. I know it is at least 4 bytes and 52 should be big enough. ;A pox on MS documentation standards. If @error Or Not $aResult1[0] Then Return _CCCFError(3,_WinAPI_GetLastError()) Local $hGlobal1 = $aResult1[0] $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hGlobal) If @error Or Not $aResult[0] Then Return _CCCFError(4,_WinAPI_GetLastError()) Local $hLock = $aResult[0] $aResult1 = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hGlobal1) If @error Or Not $aResult1[0] Then Return _CCCFError(4,_WinAPI_GetLastError()) Local $hLock1 = $aResult1[0] Local $DROPFILES = DllStructCreate("dword pFiles;" & $tagPOINT & ";bool fNC;bool fWide;wchar[" & StringLen($sFile) + 1 & "]", $hLock) If @error Then Return SetError(5, 6, False) Local $DROPFILES1 = DllStructCreate("dword CFSTR_PREFERREDDROPEFFECT", $hLock1) If @error Then Return SetError(5, 6, False) Local $tempStruct = DllStructCreate("dword;long;long;bool;bool") DllStructSetData($DROPFILES, "pFiles", DllStructGetSize($tempStruct)) DllStructSetData($DROPFILES, "X", 0) DllStructSetData($DROPFILES, "Y", 0) DllStructSetData($DROPFILES, "fNC", 0) DllStructSetData($DROPFILES, "fWide", 1) DllStructSetData($DROPFILES, 6, $sFile) For $i = 1 To StringLen($sFile) If DllStructGetData($DROPFILES, 6, $i) = $sSeparator Then DllStructSetData($DROPFILES, 6, Chr(0), $i) Next $aResult = DllCall("user32.dll", "handle", "SetClipboardData", "uint", $CF_HDROP, "handle", $hGlobal) If @error Or Not $aResult[0] Then $iError = 6 $iLastError = _WinAPI_GetLastError() EndIf DllStructSetData($DROPFILES1, "CFSTR_PREFERREDDROPEFFECT", $DROPEFFECT) $aResult1 = DllCall("user32.dll", "handle", "SetClipboardData", "uint", $PreferredDropEffect, "handle", $hGlobal1) If @error Or Not $aResult1[0] Then $iError = 6 $iLastError = _WinAPI_GetLastError() EndIf $aResult = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hGlobal) If (@error Or Not $aResult[0]) And Not $iError And _WinAPI_GetLastError() Then $iError = 8 $iLastError = _WinAPI_GetLastError() EndIf $aResult1 = DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hGlobal1) If (@error Or Not $aResult1[0]) And Not $iError And _WinAPI_GetLastError() Then $iError = 8 $iLastError = _WinAPI_GetLastError() EndIf $aResult = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hGlobal) If (@error Or $aResult[0]) And Not $iError Then $iError = 9 $iLastError = _WinAPI_GetLastError() EndIf $aResult1 = DllCall("kernel32.dll", "ptr", "GlobalFree", "handle", $hGlobal1) If (@error Or $aResult1[0]) And Not $iError Then $iError = 9 $iLastError = _WinAPI_GetLastError() EndIf Return _CCCFError($iError,$iLastError) EndFunc ;==>_ClipCopyCutFile Func _CCCFError($error=0,$extended=0) Local $aResult = DllCall("user32.dll", "bool", "CloseClipboard") If (@error Or Not $aResult[0]) And Not $error Then Return SetError(7, _WinAPI_GetLastError(), False) If $error Then Return SetError($error, $extended, False) Return True EndFunc;_CCCFError Func _ClipBoardContents() ; Determines whether files were cut or copyed to the clipboard. ; Returns 0 if clipboard is empty or does not contain ; clipboard format "HDrop". ; Returns 2 if clipboard contains cut file(s) ;(ClipBoard Format:"Preferred DropEffect" = 2 and ClipBoard Format:"HDrop"). ; Returns 5 if clipboard contains copied file(s) (ClipBoard Format:"HDrop"). ; Sets @error if clipboard does not contain at least one file (one ClipBoard Format:"HDrop"). ; Auther: BOP (JCCW) Local $CBF = 0,$CBFS,$data,$CountDropEffect2 = 0,$CountHDrop=0 Do Local $CBO = _ClipBoard_Open(0) $CBF = _ClipBoard_EnumFormats($CBF) If $CBF = 0 Then ExitLoop $CBFS = _ClipBoard_FormatStr($CBF) If $CBFS = "Preferred DropEffect" Then $data = BinaryMid(_ClipBoard_GetData($CBF),1,4) If $data = 2 Then $CountDropEffect2 +=1 EndIf If $CBFS = "HDrop" Then $CountHDrop +=1 Until Not $CBF _ClipBoard_Close() If $CountHDrop <> 1 Then Return SetError(1,1,0) If $CountDropEffect2 = 1 Then Return SetError(0,0,2) Return SetError(0,0,5) EndFunc Edited April 16, 2012 by Bop Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now