[GuiDropFile] Multiple Files Parsing - How? Level Rookie

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ZakMcKrackenDE
Posts: 11
Joined: 28 Sep 2022, 07:48

[GuiDropFile] Multiple Files Parsing - How? Level Rookie

Post by ZakMcKrackenDE » 03 Oct 2022, 04:21

Hello AHK-Humans,

sometimes AHK is easy, sometimes not. The documentation is for a rookie is not always helpful. But i love AHK.
So i ask you:

Code: Select all

GuiDropFiles:
MsgBox, % "A_GuiControl=" A_GuiControl "`n" ; on what AHK control were files dropped
            . "A_EventInfo=" A_EventInfo "`n"   ; number of files
            . "A_GuiEvent =" A_GuiEvent         ; all filenames, divided by `n
msgbox % a_guievent

Loop, Parse, A_GuiEvent, 



Return

After a multiple GuiDropFiles Event, i have the full paths from each file in the variable A_guievent. But how can i Copy each dropped files in a folder. With a single File Drop Event it works, but
how can i do this with multiple files. In other words : How can i handle the a_guievent with more than one dropped files?

I google yesterday for hours and i didn´t find any solution in rookie language.

Please in Rookie - Language, if possible.

Who can teach me?

Thanks

ZakMcKracken

garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: [GuiDropFile] Multiple Files Parsing - How? Level Rookie

Post by garry » 03 Oct 2022, 06:08

I used this for > MERGE TEXT-FILES with Drag&Drop to textfile > a_desktop . "\MyMergedTexts.txt"

Code: Select all

;-------- saved at 星期五 九月 2022-09-16  18:47 UTC --------------
;- How to merge 2 text files to 1 text file? 
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=108461

;=== SCRIPT MERGE TEXT-FILES with Drag&Drop to textfile >  a_desktop . "\MyMergedTexts.txt" ====
#Warn
#NoEnv
setworkingdir,%a_scriptdir%
filename1=TEXT_MERGE
extensions:="txt,ahk,bas,csv,bat"
F1:=a_desktop . "\MyMergedTexts.txt"
;-----------
Gui,2: Font,s14 cBlack,Lucida Console
Gui,2:Add,Text    , x20  y10  ,Drag&Drop txt-files %extensions% here :
Gui,2:add,button  , x740 y190 w100 h27  gStart1       ,Start
Gui,2:Show        , x50  y10  w860 h250               ,%Filename1%
Gui,2:add,edit    , x20  y35  w820 h135  vED1,
return
;------------
2Guiclose:
exitapp
;=========================================
2GuiDropFiles:
Guicontrolget,ED1
Loop, parse, A_GuiEvent, `n
   GuiControl,2:,ED1,%ed1%`n%A_LoopField%
GuiControl,2: Focus,ED1
send,^{end}
return
;-----------------------------------------
Start1:
Gui,2:submit,nohide
guicontrolget,ED1
i:=0
loop,parse,ed1,`n,`r
  {
  x:=a_loopfield
  if x=
     continue
  SplitPath,x, name, dir, ext, name_no_ext, drive
  if ext in %extensions%
    {
	i++
	fileappend,`r`n`r`n`r`n=================  PATH = %x%  =======================================`r`n,%f1%,utf-8   ;- add fullpath-name
    runwait, %comspec% /c type %x% >>%F1%,,hide
	fileappend,`r`n`r`n`r`n,%f1%
	}
  }
if i>0
 {  
 try
   run,%f1%
 }
else
 msgbox, 262208, ,Not found text-files %extensions%
return
;================== END SCRIPT MERGE TEXT-FILES ======================================

User avatar
ZakMcKrackenDE
Posts: 11
Joined: 28 Sep 2022, 07:48

Re: [GuiDropFile] Multiple Files Parsing - How? Level Rookie

Post by ZakMcKrackenDE » 03 Oct 2022, 06:25

Code: Select all

; EXAMPLE #1:
Loop, Parse, A_GuiEvent, `n
{
    MsgBox, 4,, File number %A_Index% is:`n%A_LoopField%.`n`nContinue?
    IfMsgBox, No, break
}

Okay, i find the solution in the documentation, but what if the Drop-Event Contains Folders an i like to seperate each file to move or copy it.?

If i understand the script right than the `n take each text in A_guievent and the A_loopfield insert the Paths. But how can i handle Folders?

I like to exam each file extensions in the folder and copy each file in a special folder.

I learn a lot. Thanks for every help.

best regards

Zak

garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: [GuiDropFile] Multiple Files Parsing - How? Level Rookie

Post by garry » 03 Oct 2022, 07:19

example : windows robocopy / drag&drop one folder/with subfolders / example HDD=E , copy to > DEST1 := hdd . ":\_MyTestFolder" ( E:\_MyTestFolder )

Code: Select all

;- windows robocopy / drag&drop one folder/with subfolders , example HDD=E , copy to > DEST1  := hdd . ":\_MyTestFolder"  
#warn
#NoEnv
setworkingdir,%a_scriptdir%
Gui,2: -dpiscale
Gui,2:Color,Black,Black
Gui,2:Font,s12 cYellow,Lucida Console
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100
;-
;----------- MAIN DESTINATION ------------------
HDD := "E"
if FileExist(HDD ":\")
 {
 DEST1  := hdd . ":\_MyTestFolder"         ;- << main destination / copies here Folder\subfolders\files
 ifnotexist,%dest1%
   filecreatedir,%dest1%
 }
else
 {  
 msgbox, 262208,Warning, HDD "%HDD%" not found.
 exitapp
 } 
;-----------------------------------------------
Menu,S1 ,add,EDIT_ThisScript         ,MH1
Menu,S2 ,add,OPEN_ThisFolder         ,MH2
Menu,S3 ,add,RELOAD                  ,MH3
menu,myMenuBar,Add,ThisScript              ,:S1
menu,myMenuBar,Add,ThisFolder              ,:S2
menu,myMenuBar,Add,RELOAD                  ,:S3
Gui,2:menu,MyMenuBar
recx:=""
dest2:=""
;-----------
text9:="SOURCE Drag & Drop only FOLDER"
x:=(wa*1)/xx,y:=(ha*1)/xx,w:=(wa*8)/xx
Gui,2:add,text,x%x% y%y% w%w%,%text9%
x:=(wa*9)/xx,y:=(ha*1)/xx,w:=(wa*40)/xx,h:=(ha*2.6)/xx
Gui,2:add,Edit, x%x%  y%y% w%w%  h%h% -vscroll vSOURCE1
;-
x:=(wa*1)/xx,y:=(ha*5)/xx,w:=(wa*15)/xx
Gui,2:add,text,x%x% y%y% w%w%,DESTINATION  :
x:=(wa*9)/xx,y:=(ha*5)/xx,w:=(wa*40)/xx,h:=(ha*2.6)/xx
Gui,2:add,Edit, x%x%  y%y% w%w%  h%h% -vscroll vDEST1x readonly,%dest1%
;-
x:=(wa*1)/xx,y:=(ha*10)/xx
Gui,2:Add, Text  , x%x%  y%y%          ,Folders=
x:=(wa*5)/xx,y:=(ha*10)/xx,w:=(wa*3)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Edit  , x%x% y%y% w%w%   h%h%  -vscroll vCount1 right readonly
;-
x:=(wa*1)/xx,y:=(ha*14)/xx
Gui,2:Add, Text  , x%x%  y%y%         ,Files=
x:=(wa*5)/xx,y:=(ha*14)/xx,w:=(wa*3)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Edit  , x%x% y%y% w%w%   h%h%  -vscroll vCount2 right readonly
;-
x:=(wa*1)/xx,y:=(ha*18)/xx,w:=(wa*6)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Button  , x%x% y%y% w%w%   h%h%  gStart vBTStart,START
;-
x:=(wa*8)/xx,y:=(ha*18)/xx,w:=(wa*15)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Edit  , x%x% y%y% w%w%   h%h%  -vscroll vText1 readonly
;-
x:=(wa*24)/xx,y:=(ha*18)/xx,w:=(wa*6)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Button  , x%x% y%y% w%w%   h%h%  gClear vBTclear,Clear
;-
x:=(wa*31)/xx,y:=(ha*18)/xx,w:=(wa*6)/xx,h:=(ha*2.6)/xx
Gui,2:Add, Button  , x%x% y%y% w%w%   h%h%  gFolder vBTFolder,FOLDER
;-
Gui,2:add,text,x0 y0 w0 h0 vT1
x:=(wa*20)/xx,y:=(ha*20)/xx,w:=(wa*50)/xx,h:=(ha*24)/xx
Gui,2:Show, x%x% y%y% w%w% h%h%,COPY
GuiControl,2:Disable,btstart
GuiControl,2:Disable,btfolder
GuiControl,2:Disable,btClear
Return
;-----------------------
2Guiclose:
if (recx=1)
  {
  msgbox, 262208,COPY ,COPY is running
  return
  }
else
  exitapp
;-----------------------
2GuiDropFiles:
AAC:=a_guievent
SplitPath,AAC, name, dir, ext, name_no_ext, drive
if ext<>
  return
Gui,2:submit,nohide
GuiControl,2:,Text1,
GuiControl,2:,count1,
GuiControl,2:,count2,
dest2:=dest1 . "\" . name
GuiControl,2:,Source1,%AAC%
GuiControl,2:,dest1x,%dest2%
;-----
filesx:=""
foldersx:=""
Loop, Files, %aac%\*.*, FR
	Filesx := A_Index
Loop, Files, %aac%\*.*, DR
	Foldersx := A_Index
GuiControl,2:,count1,%foldersx%
GuiControl,2:,count2,%filesx%
GuiControl,2:Enable,btstart
return
;----------------------
Start:
Gui,2:submit,nohide
if (source1="")
  {
  msgbox, 262208, ,SOURCE is not selected
  return
  }
GuiControl,2:,Text1,Copy is running .....
starttime  := A_TickCount
recx=1
runwait, %comspec% /c robocopy "%source1%" "%dest2%" /XO /E /UNICODE,,hide       ;- <<<< robocopy running
recx=0
aat:=(A_TickCount - starttime)//1000 
GuiControl,2:,Text1,COPY FINISHED in %aat% seconds
aat=
source1=
AAC=
GuiControl,2:Disable,btstart
GuiControl,2:Enable,btfolder
GuiControl,2:Enable,btClear
GuiControl,2: Focus, T1
return
;--------------------
clear:
AAC=
source1=
GuiControl,2:,Text1,
GuiControl,2:,Source1,
GuiControl,2:,count1,
GuiControl,2:,count2,
GuiControl,2:,dest1x,%dest1%
GuiControl,2:Disable,btstart
GuiControl,2:Disable,btfolder
GuiControl,2:Disable,btClear
return
;--------------------
Folder:
try
 run,%dest2%
return
;--------------------
mh1:
editorx1=C:\Program Files\Notepad++\notepad++.exe
ifnotexist,%editorx1%
  editorx1:=""
ifexist,%editorx1%
    run,%editorx1% "%a_scriptfullpath%"
else
  run, notepad "%a_scriptfullpath%"
return
;-----------
mh2:
run,%a_scriptdir%
return
;-----------
mh3:
if (recx=1)
  {
  msgbox, 262208,COPY ,COPY is running
  return
  }
else
 reload
return
;-----------
;=====================================================================

User avatar
ZakMcKrackenDE
Posts: 11
Joined: 28 Sep 2022, 07:48

Re: [GuiDropFile] Multiple Files Parsing - How? Level Rookie

Post by ZakMcKrackenDE » 05 Oct 2022, 04:30

Thanks garry for help :thumbup:

Post Reply

Return to “Ask for Help (v1)”