ESATU Posted May 12, 2012 Posted May 12, 2012 (edited) I have two problems here..Drag & Drop to file copy, failed to make a copy of the file ..Func File_Copy of my code below, just to copy, how to make the move a file (as FileMove)..expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Operation() Func Operation() Local $Btn_1, $Btn_2, $Msg, $From, $Dest GUICreate("Copy Files & Folders", 450, 250, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018) GUICtrlCreateLabel("Drag your file or folder you want to move into the 'From' input box, and ", 20, 30) GUICtrlCreateLabel("your target destination into the 'To' input box...", 20, 45) GUICtrlCreateLabel("From :", 30, 88) $From = GUICtrlCreateInput("", 70, 85, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("To :", 30, 113) $Dest = GUICtrlCreateInput("", 70, 110, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("", 135, 170) Opt("GUICoordMode", 2) $Btn_1 = GUICtrlCreateButton("Proceed", -1, -1, 85, 25) $Btn_2 = GUICtrlCreateButton("Cancel", 6, -1) GUISetState() While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE ExitLoop Case $Msg = $Btn_1 File_Copy($From,$Dest) Exit Case $Msg = $Btn_2 Exit EndSelect WEnd EndFunc Func File_Copy($Src_Target,$Des_Target) If Not FileExists($Des_Target) Then DirCreate($Des_Target) EndIf Local $ShFileOpStruct, $aFiles, $SourceStruct, $DestStruct, $iSourceList, $iLen, $Fo_Copy, $Fof_NoConfirmation $Fo_Copy = 0x0002 $Fof_NoConfirmation = 0x0010 $ShFileOpStruct = DllStructCreate("hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle") $aFiles = StringSplit($Src_Target, "|") For $i = 1 To $aFiles[0] $iSourceList &= $aFiles[$i] & Chr(0) Next $iSourceList &= Chr(0) & Chr(0) $iSourceList = StringToBinary($iSourceList) $iLen = BinaryLen($iSourceList) $SourceStruct = DllStructCreate("byte[" & $iLen & "]") DllStructSetData($SourceStruct, 1, $iSourceList) $DestStruct = DllStructCreate("char[" & StringLen($Des_Target) + 2 & "]") DllStructSetData($DestStruct, 1, $Des_Target) DllStructSetData($DestStruct, 1, 0, StringLen($Des_Target) + 1) DllStructSetData($DestStruct, 1, 0, StringLen($Des_Target) + 2) DllStructSetData($ShFileOpStruct, "hWnd", 0) DllStructSetData($ShFileOpStruct, "wFunc", $Fo_Copy) DllStructSetData($ShFileOpStruct, "pFrom", DllStructGetPtr($SourceStruct)) DllStructSetData($ShFileOpStruct, "pTo", DllStructGetPtr($DestStruct)) DllStructSetData($ShFileOpStruct, "fFlags", $Fof_NoConfirmation) DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($ShFileOpStruct)) EndFuncI hope to get help from you all on this forum ... if no help for both my problem, one of it can be solved is enough for me... Edited May 12, 2012 by ESATU
Moderators Melba23 Posted May 12, 2012 Moderators Posted May 12, 2012 ESATU,Why not use the FileCopy and FileMove functions directly? Why the complex code? M23P.S. This works fine for me:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Operation() Func Operation() GUICreate("Copy Files & Folders", 450, 250, -1, -1, Default, $WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Drag your file or folder you want to move into the 'From' input box, and ", 20, 30) GUICtrlCreateLabel("your target destination into the 'To' input box...", 20, 45) GUICtrlCreateLabel("From :", 30, 88) $From = GUICtrlCreateInput("", 70, 85, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("To :", 30, 113) $Dest = GUICtrlCreateInput("", 70, 110, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("", 135, 170) ;Opt("GUICoordMode", 2) $Btn_1 = GUICtrlCreateButton("Proceed", -1, -1, 85, 25) $Btn_2 = GUICtrlCreateButton("Cancel", 6, -1) GUISetState() While 1 Switch GUIGetMsg() Case $Btn_1 If File_Copy($From,$Dest) Then MsgBox(0, "Success", "File was copied") Else MsgBox(0, "Error", "File was not copied") EndIf ContinueCase Case $GUI_EVENT_CLOSE, $Btn_2 Exit EndSwitch WEnd EndFunc Func File_Copy($Src_Target,$Des_Target) ; Read inputs $Src_Target = GUICtrlRead($Src_Target) $Des_Target = GUICtrlRead($Des_Target) ; Check source exists and is file If Not FileExists($Src_Target) Then Return 0 Else If StringInStr(FileGetAttrib($Src_Target), "D", 1) Then Return 0 EndIf EndIf ; Check target exists and is a folder If Not FileExists($Des_Target) Then If Not DirCreate($Des_Target) Then Return 0 EndIf Else If Not StringInStr(FileGetAttrib($Des_Target), "D", 1) Then Return 0 EndIf EndIf ; Copy file If FileCopy($Src_Target, $Des_Target, 1) Then Return 1 Else Return 0 EndIf EndFunc Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
IanN1990 Posted May 12, 2012 Posted May 12, 2012 (edited) I dont think he means to overly complex but rather when people dont know the best functions for the problem, the code inherently ends up being alot more complex Edited May 12, 2012 by IanN1990
kylomas Posted May 13, 2012 Posted May 13, 2012 (edited) M23, What is the purpose of the highlighted stmt?expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Operation() Func Operation() GUICreate("Copy Files & Folders", 450, 250, -1, -1, Default, $WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Drag your file or folder you want to move into the 'From' input box, and ", 20, 30) GUICtrlCreateLabel("your target destination into the 'To' input box...", 20, 45) GUICtrlCreateLabel("From :", 30, 88) $From = GUICtrlCreateInput("", 70, 85, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("To :", 30, 113) $Dest = GUICtrlCreateInput("", 70, 110, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) [b]GUICtrlCreateLabel("", 135, 170)[/b] ;Opt("GUICoordMode", 2) $Btn_1 = GUICtrlCreateButton("Proceed", -1, -1, 85, 25) $Btn_2 = GUICtrlCreateButton("Cancel", 6, -1) GUISetState() While 1 Switch GUIGetMsg() Case $Btn_1 If File_Copy($From,$Dest) Then MsgBox(0, "Success", "File was copied") Else MsgBox(0, "Error", "File was not copied") EndIf ContinueCase Case $GUI_EVENT_CLOSE, $Btn_2 Exit EndSwitch WEnd EndFunc Func File_Copy($Src_Target,$Des_Target) ; Read inputs $Src_Target = GUICtrlRead($Src_Target) $Des_Target = GUICtrlRead($Des_Target) ; Check source exists and is file If Not FileExists($Src_Target) Then Return 0 Else If StringInStr(FileGetAttrib($Src_Target), "D", 1) Then Return 0 EndIf EndIf ; Check target exists and is a folder If Not FileExists($Des_Target) Then If Not DirCreate($Des_Target) Then Return 0 EndIf Else If Not StringInStr(FileGetAttrib($Des_Target), "D", 1) Then Return 0 EndIf EndIf ; Copy file If FileCopy($Src_Target, $Des_Target, 1) Then Return 1 Else Return 0 EndIf EndFunc Thanks, kylomas Edit: cannot get this editor to bold the text. the stmt I am asking about has bold tags around it Edited May 13, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
ESATU Posted May 13, 2012 Author Posted May 13, 2012 Sorry, I am new in AutoIt and English is not my first language... and thanks to all for trying to help.. after four hours keep trying, I successfully completed my first problem own... expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $Inbox1, $Inbox2 Operation() Func Operation() Local $Btn_1, $Btn_2, $Msg GUICreate("Copy Files & Folders", 450, 250, -1, -1, Default, $WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Drag your file or folder you want to move into the 'From' input box, and" & @CRLF & _ "your target destination into the 'To' input box...", 20, 30) GUICtrlCreateLabel("From :", 30, 88) $Inbox1 = GUICtrlCreateInput("", 70, 85, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("To :", 30, 113) $Inbox2 = GUICtrlCreateInput("", 70, 110, 340, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("", 135, 170) Opt("GUICoordMode", 2) $Btn_1 = GUICtrlCreateButton("Proceed", -1, -1, 85, 25) $Btn_2 = GUICtrlCreateButton("Cancel", 6, -1) GUISetState() While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE ExitLoop Case $Msg = $Btn_1 Start() Exit Case $Msg = $Btn_2 Exit EndSelect WEnd EndFunc Func Start() Local $From, $Dest $From = GUICtrlRead($Inbox1) $Dest = GUICtrlRead($Inbox2) File_Copy($From,$Dest) MsgBox(0, "Process", "copying the files have been completed...") Exit EndFunc Func File_Copy($Src_Target,$Des_Target);it will copy files and replace all the files without Yes, Yes to All, No and Cancel confirmation box with Windows progress bar... If Not FileExists($Des_Target) Then DirCreate($Des_Target) EndIf Local $ShFileOpStruct, $aFiles, $SourceStruct, $DestStruct, $iSourceList, $iLen, $Fo_Copy, $Fof_NoConfirmation $Fo_Copy = 0x0002 $Fof_NoConfirmation = 0x0010 $ShFileOpStruct = DllStructCreate("hwnd hWnd;uint wFunc;ptr pFrom;ptr pTo;int fFlags;int fAnyOperationsAborted;ptr hNameMappings;ptr lpszProgressTitle") $aFiles = StringSplit($Src_Target, "|") For $i = 1 To $aFiles[0] $iSourceList &= $aFiles[$i] & Chr(0) Next $iSourceList &= Chr(0) & Chr(0) $iSourceList = StringToBinary($iSourceList) $iLen = BinaryLen($iSourceList) $SourceStruct = DllStructCreate("byte[" & $iLen & "]") DllStructSetData($SourceStruct, 1, $iSourceList) $DestStruct = DllStructCreate("char[" & StringLen($Des_Target) + 2 & "]") DllStructSetData($DestStruct, 1, $Des_Target) DllStructSetData($DestStruct, 1, 0, StringLen($Des_Target) + 1) DllStructSetData($DestStruct, 1, 0, StringLen($Des_Target) + 2) DllStructSetData($ShFileOpStruct, "hWnd", 0) DllStructSetData($ShFileOpStruct, "wFunc", $Fo_Copy) DllStructSetData($ShFileOpStruct, "pFrom", DllStructGetPtr($SourceStruct)) DllStructSetData($ShFileOpStruct, "pTo", DllStructGetPtr($DestStruct)) DllStructSetData($ShFileOpStruct, "fFlags", $Fof_NoConfirmation) DllCall("shell32.dll", "int", "SHFileOperation", "ptr", DllStructGetPtr($ShFileOpStruct)) EndFunc copy files and replace all the files without Yes, Yes to All, No and Cancel confirmation box with Windows progress bar... also can.. Func File_Copy($FromFile,$Tofile);it will copy files with Yes, Yes to All, No and Cancel confirmation box with Windows progress bar... Local $FromFile, $Tofile, $winShell $winShell = ObjCreate("shell.application") $winShell.namespace($Tofile).CopyHere($FromFile) EndFunc copy files with Yes, Yes to All, No and Cancel confirmation box with Windows progress bar... it works perfectly with the file copy ... but if there is anyone who can help me to solve change the FileCopy function to the FileMove function, I am very grateful and appreciate it...
Moderators Melba23 Posted May 13, 2012 Moderators Posted May 13, 2012 kylomas,What is the purpose of the highlighted stmt?Best you ask ESATU - it was in his original script. ESATU,I successfully completed my first problem ownCongratulations. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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