Batch comparing variables Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
IvanVanko
Posts: 34
Joined: 14 Jul 2016, 11:40

Batch comparing variables

06 Nov 2016, 06:16

Hi guys!
Let's say I have a variables from name1 to name6 and they are keeping file names. And I have a different code with different labels to download them, like download1 to download 6. To download all I do gosub download for each file, file 2 should be latest as it always biggest.

Code: Select all

Gui, Add, Button, -Wrap Default w100 h30 gDownload1, Download file 1 
Gui, Add, Button, -Wrap Default w100 h30 gDownload2, Download file 2 
Gui, Add, Button, -Wrap Default w100 h30 gDownload3, Download file 3 
Gui, Add, Button, -Wrap Default w100 h30 gDownload4, Download file 4 
Gui, Add, Button, -Wrap Default w100 h30 gDownload5, Download file 5 
Gui, Add, Button, -Wrap Default w100 h30 gDownload6, Download file 6
Gui, Add, Button, -Wrap Default w100 h30 gDownloadall, Download all
Gui, Show, w200 h300, Some junk

name1 = filename1
name2 = filename1
name3 = filename1
name4 = filename4
name5 = filename5
name6 = filename6
return

download1:
Currentname = %name1%
goto, downloader

download2:
Currentname = %name2%
goto, downloader

download3:
Currentname = %name3%
goto, downloader

download4:
Currentname = %name4%
goto, downloader

download5:
Currentname = %name5%
goto, downloader

download6:
Currentname = %name6%
goto, downloader

downloader:
msgbox, Downloading %currentname%!
return 

downloadall:
gosub, download1
gosub, download3
gosub, download4
gosub, download5
gosub, download6
gosub, download2 ;should be latest as it almost always the biggest file

GuiClose:
ExitApp
Questions:
1) Sometimes there could be same files in different positions, how could I compare them all between each other and then skip duplicates without a lot of if name1 = %name2%, etc.?
2) Could I optimise somehow this download1 - download6 section, because only difference between them is in the numbers? Loop would not work as I am assigning variable there.
Твой софт - говно!
ahcahc
Posts: 110
Joined: 25 Jul 2014, 23:55

Re: Batch comparing variables  Topic is solved

06 Nov 2016, 10:32

Code: Select all

downloadall:
list =
loop, 6
	list .= (list?"`n":"") name%a_index%
sort, list, U		;removes duplicate items
loop, parse, list, `n
{
	currentname := A_LoopField
	gosub, downloader
}
return
garry
Posts: 2217
Joined: 22 Dec 2013, 12:50

Re: Batch comparing variables

06 Nov 2016, 16:43

thank you ahcahc
here a script uses one startbutton for different links

Code: Select all

#warn
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1

Gui,2:Color, Black
Gui,2:Color, ControlColor, Black
Gui,2:Font,cDefault,Fixedsys

list :=""

fd=%a_desktop%\MUSIC_TEST
ifnotexist,%fd%
  filecreatedir,%fd%

names:="
(Join|
Name1  ; http://tapahtumaturku.fi/nothingpersonal.org/humppa/Olavi%20Virta%20-%20Eeva.mp3
Name2  ; http://tapahtumaturku.fi/nothingpersonal.org/humppa/Olavi%20Virta%20-%20Eeva.mp3
Name3  ; http://tapahtumaturku.fi/nothingpersonal.org/humppa/Olavi%20Virta%20-%20Eeva.mp3
Name4  ; http://www.replicaradio.ro/audio/billboard/1960/93.Guy%20Mitchell-Heartaches%20By%20The%20Number.mp3
Name5  ; http://www.replicaradio.ro/audio/billboard/1960/02.Jim%20Reeves-He'll%20Have%20To%20Go.mp3
Name6  ; http://www.replicaradio.ro/audio/billboard/1960/16.Marty%20Robbins-El%20Paso.mp3
"
)
stringsplit,g,names,|
           total1:=g0

loop,%total1%
  {
  loop,parse,names,`|
     {
     url%a_index%  :=""
     namex%a_index%:=""
     x=%a_loopfield%
     stringreplace,x,x,|,,all
     stringsplit,h,x,`;
     list .= h2 . "`r`n"
     }
  }
sort, list, U
i=0

gui,2:add,text,section x40   y10 w0 h0,    ;-- set position
loop, parse, list, `n,`r
 {
 i++
 if (a_loopfield="")
    break
 currentname := A_LoopField
 SplitPath,currentname, name, dir, ext, name_no_ext, drive
 url%a_index%   .= currentname
 namex%a_index% .= name
 str:=uriDecode(name_no_ext)
 Gui,2:Add,Button, xp   y+7 h23 w500 vIB%a_index% gStartButton,%str%
 }

Gui,2:Add,Edit   , xp   y+15 w500 h23 vED1 cYellow readonly,
Gui,2:Add,Button , xp   y+15 w150 h23 gDownloadAll,Download-ALL

loop,%i%
  ib%a_index%:=a_index
Gui,2:show,x100 y20,TEST
return
;---------------------------
2guiclose:
exitapp
;---------------------------
startbutton:
Gui,2:submit,nohide
r:=%a_GuiControl%
if r=
  return
e:=url%r%
k:=namex%r%
str:=uriDecode(k)
;msgbox,urldownloadtofile`, %e%`,%fd%\%str%
GuiControl, 2:, ED1, Download... %str%
urldownloadtofile, %e%,%fd%\%str%
GuiControl, 2:, ED1, Finished
run,%fd%\%str%
return
;---------------------------
DownloadAll:
Gui,2:submit,nohide
loop,parse,list,`n,`r
 {
 y=%a_loopfield%
 if (y="")
    break
 SplitPath,y, name, dir, ext, name_no_ext, drive
 str:=uriDecode(name)
 ;msgbox, 262208, , urldownloadtofile`,%y%`,%fd%\%str%,2
 GuiControl, 2:, ED1, Download... %str%
 urldownloadtofile,%y%,%fd%\%str%
 GuiControl, 2:, ED1, Finished
 }
run,%fd%
return
;---------------------------
uriDecode(str)
{
; Find uri encoded characters such as %20 (space) and replace with ascii character
pos = 1
Loop
  If pos := RegExMatch(str, "i)(?<=%)[\da-f]{2}", hex, pos++)
StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
Else Break
Return, str
}
;================= end script =============================================

User avatar
IvanVanko
Posts: 34
Joined: 14 Jul 2016, 11:40

Re: Batch comparing variables

09 Nov 2016, 05:30

ahcahc, garry, awesome examples, thank you very much!
Твой софт - говно!

Return to “Ask For Help”

Who is online

Users browsing this forum: Chiefkes, freakkk, Google [Bot], msaeternal, TAC109, Yakshongas, yalsch and 197 guests