Sign in to follow this  
Followers 0
ESATU

Drag & Drop for FileMove

6 posts in this topic

#1 ·  Posted (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)..
#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))
EndFunc

I 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 by ESATU

Share this post


Link to post
Share on other sites



ESATU,

Why not use the FileCopy and FileMove functions directly? Why the complex code? ;)

M23

P.S. This works fine for me:

#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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by IanN1990

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

M23,

What is the purpose of the highlighted stmt?

#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 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

Share this post


Link to post
Share on other sites

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...

#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...

Share this post


Link to post
Share on other sites

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 own

Congratulations. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0