Filecopy Via Drag and Drop - Problem

  • Hallo Autoit.de,

    ich habe folgendes vor.
    Ich möchte über eine GUI und einer Editbox via Drag and Drop Files kopieren.

    Alles bis auf das kopieren funktioniert.
    Ich verstehe einfach nicht, warum er das "eingeworfene" File nicht auf ein anderen Testordner schiebt.

    Ich würde mich über eure Hilfe sehr freuen.
    Hier mein Code:

    [autoit]

    #include <GUIConstantsEx.au3>

    [/autoit][autoit][/autoit][autoit]

    Opt('MustDeclareVars', 1)

    [/autoit][autoit][/autoit][autoit]

    Example()

    [/autoit][autoit][/autoit][autoit]

    Func Example()
    Local $file, $btn, $msg, $filepath, $take, $dest

    GUICreate(" GUI input", 300, 300, 400, 400, -1, 0x00000018)
    $file = GUICtrlCreateedit("", 20, 5, 250, 200)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    ;~ GUICtrlCreateInput("", 10, 35, 300, 20)
    $btn = GUICtrlCreateButton("Ok", 220, 250, 50, 20)

    [/autoit][autoit][/autoit][autoit]

    $dest = @ScriptDir & "\test"

    [/autoit][autoit][/autoit][autoit]

    GUISetState()

    [/autoit][autoit][/autoit][autoit]

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()

    $filepath = GUICtrlRead($file)


    if $filepath <> "" Then

    Filecopy($filepath,$dest,1)

    Sleep(500)

    GUICtrlSetData($file,"")

    Sleep(500)

    EndIf


    Select
    Case $msg = $btn
    ExitLoop
    EndSelect


    WEnd

    [/autoit][autoit][/autoit][autoit]

    EndFunc

    [/autoit]
  • Das Problem ist, dass der Zeilenumbruch auch mit im Dateinamen ist.

    Füg folgende Zeile in dein Script ein:

    [autoit]

    $filepath = StringReplace($filepath, @CRLF, "")

    [/autoit]

    E

    Edit:
    Bei deinem Script wird auch kopiert wenn der User per Tastatur etwas in das Editfeld schreibt!
    Um das zu verhindern, solltest du $GUI_EVENT_DROPPED verwenden:

    [autoit]

    #include <GUIConstantsEx.au3>

    [/autoit][autoit][/autoit][autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit][autoit][/autoit][autoit]

    $sDest = @ScriptDir & "\Test"

    [/autoit][autoit][/autoit][autoit]

    $hGui = GUICreate("Test", 320, 240, -1, -1, -1, 0x00000018)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUISetOnEvent($GUI_EVENT_DROPPED, "_DragNDrop")
    $cEdit = GUICtrlCreateEdit("", 10, 10, 300, 220)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUISetState()

    [/autoit][autoit][/autoit][autoit]

    While Sleep(100)
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func _DragNDrop()
    Local $sPath = StringReplace(@GUI_DragFile, @CRLF, "")
    ConsoleWrite('kopiere "' & $sPath & '" => "' & $sDest & '"' & @CRLF)
    FileCopy($sPath, $sDest, 1)
    EndFunc ;==>_DragNDrop

    [/autoit][autoit][/autoit][autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]