jim1 Posted March 24, 2009 Share Posted March 24, 2009 i made a gui that u can drop files in a box and u canuse them with @GUI_DRAGFILE. Thr problem is if u drop file and press a button it will create folders andcopy files in folders, but if u put another file and press another button it will create other folders and will move the newly dropped file to the new folder. now i want to make a messagebox that it will say the path of the files dropped how i can do that? Link to comment Share on other sites More sharing options...
DaRam Posted March 24, 2009 Share Posted March 24, 2009 You have almost answered your own question.@GUI_DRAGFILE contains the path to the dropped file, determine where the path ends (\ character) using StringInStr and extract the path alone using StringLeft. Link to comment Share on other sites More sharing options...
jim1 Posted March 24, 2009 Author Share Posted March 24, 2009 hmm how exactly i use both strings i tried something like that but didnt worked. if $msg = $but8 Then $result = StringInStr(@gui_dragfile, 3) msgbox(1,"paths",$result) EndIf Link to comment Share on other sites More sharing options...
DaRam Posted March 24, 2009 Share Posted March 24, 2009 $pos = StringInStr(@gui_dragfile, "\") msgbox(1, "path", StringLeft(@gui_dragfile, $pos - 1)) Link to comment Share on other sites More sharing options...
jim1 Posted March 24, 2009 Author Share Posted March 24, 2009 thanks for ur help i have 2 questions does \ means it that it will search for path? whats that -1 near $pos? i tried to use it but the only thing it saws is c: even if i put more than 1 file Link to comment Share on other sites More sharing options...
DaRam Posted March 24, 2009 Share Posted March 24, 2009 Ok there was a mistake in my code, it should actually have looked from the right to find the last "\" character. The StringInStr is looking for the path separator character "\" The -1 of the result ($pos) is looking 1 character less than the position found. This code (from File.Au3) might give you a better idea of how the additional parameters for StringInStr can be used to look from the left or right: Local $nPosForward = StringInStr($szPath, "/", 0, -1) Local $nPosBackward = StringInStr($szPath, "\", 0, -1) If $nPosForward >= $nPosBackward Then $pos = $nPosForward Else $pos = $nPosBackward EndIf $dir = StringLeft($szPath, $pos) $fname = StringRight($szPath, StringLen($szPath) - $pos) Modify the code above replacing $szPath with @GUI_DRAGFILE and the $dir variable will contain the path. As far as getting multiple files, I do not know which part of your GUI is accepting drag and dropped files. If it is an Input control, then you would parse the contents of the input ctrl (The files should be separated by | characters). thanks for ur help i have 2 questions does \ means it that it will search for path? whats that -1 near $pos? i tried to use it but the only thing it saws is c: even if i put more than 1 file Link to comment Share on other sites More sharing options...
jim1 Posted March 24, 2009 Author Share Posted March 24, 2009 i replaced it with gui_dragfile but it doesnt do anything. Files dropped are in listbox expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> Opt('GUIResizeMode', 802) $Form1 = GUICreate("Diaulos beta v1.0", 633, 210, -1, -1, -1, $WS_EX_ACCEPTFILES) $Name = GUICtrlCreateInput("Name", 8, 24, 145, 21) $Label1 = GUICtrlCreateLabel("Enter name here", 32, 4, 82, 17) $Label2 = GUICtrlCreateLabel("Choose lesson", 36, 52, 73, 17) $But1 = GUICtrlCreateButton("Chemistry", 8, 84, 125, 21, 0) $But2 = GUICtrlCreateButton("Physic", 8, 108, 125, 21, 0) $But3 = GUICtrlCreateButton("Biology", 8, 132, 125, 21, 0) $But4 = GUICtrlCreateButton("Rar folder", 525, 24, 97, 21, 0) $But9 = GUICtrlCreateButton("Preview", 525, 48, 97, 21, 0) $But5 = GUICtrlCreateButton("Send files", 525, 72, 97, 21, 0) $but8 = GUICtrlCreateButton("Create Folder", 156, 24, 145, 21, 0) $Label3 = GUICtrlCreateLabel("Drop files in box below", 320, 4, 110, 17) $input4 = GUICtrlCreateInput("Write comments here", 12, 220, 301, 125) $input5 = GUICtrlCreateInput("Name", 328, 220, 145, 21) $Input1 = GUICtrlCreateInput("Surname", 328, 248, 145, 21) $Input2 = GUICtrlCreateInput("Job", 328, 276, 145, 21) $Input3 = GUICtrlCreateInput("Phone", 328, 304, 145, 21) $cListBox = GUICtrlCreateList("", 250, 75, 250, 120) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $But6 = GUICtrlCreateButton("(Not allowed)", 20, 172, 33, 33, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) GUICtrlSetImage($but6, "images\arrow_down.bmp", 0) $But7 = GUICtrlCreateButton("(Not allowed)", 68, 172, 33, 33, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) GUICtrlSetImage($but7, "images\arrow_up.bmp", 0) GUISetState(@SW_SHOW) While 1 $Msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE DirRemove(@ScriptDir & "\teacher1files\" & GUICtrlRead($Name), 1) Exit Case $GUI_EVENT_DROPPED GUICtrlSetData($cListBox, @GUI_DRAGFILE & @CRLF, 1) EndSwitch if $msg = $But4 Then Dim $sWinRAR = @ScriptDir & '\winrar\' Run($sWinRAR & 'winrar a ".\t1files" ".\teacher1files"') EndIf If $msg = $But5 then SoundPlay("Sounds/Connecting.mp3") EndIf if $msg = $But3 then SoundPlay("Sounds/bio.mp3") DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name) &"\Biology") Filecopy(@GUI_DRAGFILE , @scriptdir & "\teacher1files\" & GUICtrlRead($Name) & "\" & guictrlread($But3) & "\") EndIf if $msg = $But1 then SoundPlay("") DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name) &"\Chemistry") Filecopy(@GUI_DRAGFILE , @scriptdir & "\teacher1files\" & GUICtrlRead($Name) & "\" & guictrlread($But1) & "\") EndIf if $msg = $But2 then SoundPlay("Sounds/Physic.mp3") DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name) &"\Physic") Filecopy(@GUI_DRAGFILE , @scriptdir & "\teacher1files\" & GUICtrlRead($Name) & "\" & guictrlread($But2) & "\") EndIf if $msg = $but8 Then DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name)) EndIf if $msg = $but6 Then WinMove("","",Default,Default,665,388) endif If $msg = $but7 Then winmove("","",default,default,665,242) EndIf if $msg = $but9 Then Local $nPosForward = StringInStr(@gui_dragfile, "/", 0, -1) Local $nPosBackward = StringInStr(@gui_dragfile, "\", 0, -1) If $nPosForward >= $nPosBackward Then $pos = $nPosForward Else $pos = $nPosBackward EndIf $dir = StringLeft(@gui_dragfile, $pos) $fname = StringRight(@gui_dragfile, StringLen(@gui_dragfile) - $pos) EndIf WEnd Link to comment Share on other sites More sharing options...
DaRam Posted March 24, 2009 Share Posted March 24, 2009 i replaced it with gui_dragfile but it doesnt do anything. Try this (do read comments left in the code): expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GuiListBox.au3> #include <Array.au3> ; Drop Multiple files Code based on LazyCat's code http://www.autoitscript.com/forum/index.php?showuser=126 Global $WM_DROPFILES = 0x233 Global $gaDropFiles[1] Opt('GUIResizeMode', 802) $Form1 = GUICreate("Diaulos beta v1.0", 633, 210, -1, -1, -1, $WS_EX_ACCEPTFILES) $Name = GUICtrlCreateInput("Name", 8, 24, 145, 21) $Label1 = GUICtrlCreateLabel("Enter name here", 32, 4, 82, 17) $Label2 = GUICtrlCreateLabel("Choose lesson", 36, 52, 73, 17) $But1 = GUICtrlCreateButton("Chemistry", 8, 84, 125, 21, 0) $But2 = GUICtrlCreateButton("Physic", 8, 108, 125, 21, 0) $But3 = GUICtrlCreateButton("Biology", 8, 132, 125, 21, 0) $But4 = GUICtrlCreateButton("Rar folder", 525, 24, 97, 21, 0) $But9 = GUICtrlCreateButton("Preview", 525, 48, 97, 21, 0) $But5 = GUICtrlCreateButton("Send files", 525, 72, 97, 21, 0) $but8 = GUICtrlCreateButton("Create Folder", 156, 24, 145, 21, 0) $Label3 = GUICtrlCreateLabel("Drop files in box below", 320, 4, 110, 17) $input4 = GUICtrlCreateInput("Write comments here", 12, 220, 301, 125) $input5 = GUICtrlCreateInput("Name", 328, 220, 145, 21) $Input1 = GUICtrlCreateInput("Surname", 328, 248, 145, 21) $Input2 = GUICtrlCreateInput("Job", 328, 276, 145, 21) $Input3 = GUICtrlCreateInput("Phone", 328, 304, 145, 21) $cListBox = GUICtrlCreateList("", 250, 75, 250, 120) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $But6 = GUICtrlCreateButton("(Not allowed)", 20, 172, 33, 33, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) GUICtrlSetImage($but6, "images\arrow_down.bmp", 0) $But7 = GUICtrlCreateButton("(Not allowed)", 68, 172, 33, 33, BitOr($GUI_SS_DEFAULT_BUTTON, $BS_BITMAP)) GUICtrlSetImage($but7, "images\arrow_up.bmp", 0) GUISetState(@SW_SHOW) GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC") Local $I, $J, $str = "" While 1 $Msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE DirRemove(@ScriptDir & "\teacher1files\" & GUICtrlRead($Name), 1) ExitLoop Case $GUI_EVENT_DROPPED ;Msgbox(0, "Files", @GUI_DRAGFILE) ;GUICtrlSetData($cListBox, @GUI_DRAGFILE & @CRLF, 1) $str = "" For $i = 0 To UBound($gaDropFiles) - 1 $str &= "|" & $gaDropFiles[$i] Next GUICtrlSetData($cListBox, $str) ;Msgbox(0, "Files", $str) Case $But4 Dim $sWinRAR = @ScriptDir & '\winrar\' Run($sWinRAR & 'winrar a ".\t1files" ".\teacher1files"') Case $But5 SoundPlay("Sounds/Connecting.mp3") Case $But3 SoundPlay("Sounds/bio.mp3") DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name) &"\Biology") Filecopy(@GUI_DRAGFILE , @scriptdir & "\teacher1files\" & GUICtrlRead($Name) & "\" & guictrlread($But3) & "\") Case $But1 SoundPlay("") DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name) &"\Chemistry") Filecopy(@GUI_DRAGFILE , @scriptdir & "\teacher1files\" & GUICtrlRead($Name) & "\" & guictrlread($But1) & "\") Case $But2 SoundPlay("Sounds/Physic.mp3") DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name) &"\Physic") Filecopy(@GUI_DRAGFILE , @scriptdir & "\teacher1files\" & GUICtrlRead($Name) & "\" & guictrlread($But2) & "\") Case $but8 DirCreate(@SCRIPTDIR &"\teacher1files\"& GUICtrlRead($Name)) Case $but6 WinMove("","",Default,Default,665,388) Case $but7 winmove("","",default,default,665,242) Case $but9 $J = _GUICtrlListBox_GetCount($cListBox) - 1 $str = "" for $i = 0 to $J if $i = 0 Then $str = _GUICtrlListBox_GetText($cListBox,$i) Else $str = $str & '|' & _GUICtrlListBox_GetText($cListBox,$i) EndIf Next ; $str now contains a | separated list of files in the Listbox ; Do what you want with it. $str = StringSplit($str, "|") _ArrayDisplay($str, "Files in List") Msgbox (0, "File Paths", "First File Path=" & PathOnly($str[1]) & @CRLF & "Last File Path=" & PathOnly($str[$str[0]]) ) EndSwitch WEnd Func PathOnly($PathAndFile) Local $nPosForward = StringInStr($PathAndFile, "/", 0, -1) Local $nPosBackward = StringInStr($PathAndFile, "\", 0, -1) Local $Path If $nPosForward >= $nPosBackward Then $pos = $nPosForward Else $pos = $nPosBackward EndIf $Path = StringLeft($PathAndFile, $pos) ;$filename = StringRight($PathAndFile, StringLen($PathAndFile) - $pos) Return $Path EndFunc Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam) Local $nSize, $pFileName, $I Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255) For $i = 0 To $nAmt[0] - 1 $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) $nSize = $nSize[0] + 1 $pFileName = DllStructCreate("char[" & $nSize & "]") DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize) ReDim $gaDropFiles[$i+1] $gaDropFiles[$i] = DllStructGetData($pFileName, 1) $pFileName = 0 Next EndFunc Link to comment Share on other sites More sharing options...
jim1 Posted March 25, 2009 Author Share Posted March 25, 2009 thanks for ur help a lot, any idea how to find path of the same files but copied one in the new folders. Dont know where to start from, what commands may help? Link to comment Share on other sites More sharing options...
DaRam Posted March 25, 2009 Share Posted March 25, 2009 Give it a try re-using the provided PathOnly Func. Post what you have and we'll try to help.thanks for ur help a lot, any idea how to find path of the same files but copied one in the new folders. Dont know where to start from, what commands may help? 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