Show for compare fileList1 and fileList2 Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Show for compare fileList1 and fileList2

30 Apr 2018, 12:43

Hi, everyone
the following code for A folder comparison, it's from here:
https://autohotkey.com/boards/viewtopic ... 30#p204630
Script works with privilege.

Code: Select all

#SingleInstance, Ignore
{
dir1 := ""
dir2 := ""
fileMask := ""
gosub, DoTheWork

Gui Add, ListBox, w530 r10 vfiles1, % "Dir1 = " dir1 "| |" list1
Gui Add, ListBox, w530 r10 vfiles2, % "Dir2 = " dir2 "| |" list2


Gui Add, Button, w50 gGuiOK default, OK
Gui Add, Button, x+10 w50 gGuiClose, Cancel
Gui,Add, Text, yp+5 x138,Dir1
Gui,Add, Edit, yp-3 x160 w90 vDir1,%dir1%
Gui,Add, Text, yp+2 x258,Dir2
Gui,Add, Edit, yp-3 x282 w90 vDir2,%dir2%
Gui,Add, Text, yp+2 x396,Mask
Gui,Add, Edit, yp-3 x423 w40 vFileMask,%fileMask%
Gui Add, Button, yp x483 w60 gGo, Go
;Gui Show, w1200
Gui Show, w550
Return

Go:
    Gui, Submit, NoHide 
    gosub, DoTheWork
    GuiControl,,files1,% "|Dir1 = " dir1 "| |" list1
    GuiControl,,files2,% "|Dir2 = " dir2 "| |" list2
return

GuiOK:
GuiClose:
GuiEscape:
ExitApp

DoTheWork:
filelist1 := filelist2 := ""    
list1 := list2 := ""    
Loop %dir1%\%fileMask%
{
If ( A_LoopFileName ~= "~\$")
        continue
    fileList1 .= A_LoopFileName . "`n"
    fnb1 := A_Index
}
StringTrimRight fileList1, fileList1, 1
Loop %dir2%\%fileMask%
{
    If ( A_LoopFileName ~= "~\$")
        continue
    fileList2 .= A_LoopFileName . "`n"
    fnb2 := A_Index
}
StringTrimRight fileList2, fileList2, 1

Sort fileList1
Sort fileList2
StringSplit files_1_, fileList1, `n
StringSplit files_2_, fileList2, `n
idxF1 := idxF2 := 1

Loop
{
    If (files_1_%idxF1% = files_2_%idxF2%)
    {
        ; We are in synch
        list1 .= files_1_%idxF1% . "|"
        idxF1++
        list2 .= files_2_%idxF2% . "|"
        idxF2++
    }
    Else
    {
        ; Either file at idxF1 or at idxF3 is missing, we must find which one
        If (files_1_%idxF1% > files_2_%idxF2%)
        {
            ; Missing in first list
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Else
        {
            ; Missing in second list
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
    }
    If (idxF1 > fnb1)
    {
        Loop % fnb2 - idxF2 + 1
        {
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Break
    }
    If (idxF2 > fnb2)
    {
        Loop % fnb1 - idxF1 + 1
        {
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
        Break
    }
}
StringTrimRight list1, list1, 1
StringTrimRight list2, list2, 1
Return
}
But when I've added following part to it, which contains 3 hotkey to set the folder path and file type:

Code: Select all

SetTitleMatchMode, 1
#IfWinActive, Comparison
$1::
ControlSetText, Edit1, E:\ask\work
ControlSetText, Edit2, E:\ask\backup
ControlSetText, Edit3, *.docx
ControlClick, Go, Comparison  
return
;;--------------------------------------------------- 
$2::
ControlSetText, Edit1, E:\ask\sales
ControlSetText, Edit2, E:\ask\work
ControlSetText, Edit3, *.pdf
ControlClick, Go, Comparison  
return
;;--------------------------------------------------- 
$3::
ControlSetText, Edit1, E:\ask\sales
ControlSetText, Edit2, E:\ask\backup
ControlSetText, Edit3, *.txt
ControlClick, Go, Comparison  
return
;;--------------------------------------------------- 
The code does not work well until the first time. see in the attached picture(1)
first time.png
first time.png (9.26 KiB) Viewed 1082 times
. Everything is true.
But the following times are not correct Unless you are reloading or if you close the program and reopen it. see The error in the attached picture(2).
After the first time.png
After the first time.png (10.92 KiB) Viewed 1082 times
Can anyone correct this error?
Any help would be greatly appreciated.
just me
Posts: 7401
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Show for compare fileList1 and fileList2  Topic is solved

01 May 2018, 03:25

You might try this (untested) version. Changes are marked with ; <<<<<:

Code: Select all

DoTheWork:
filelist1 := filelist2 := ""
list1 := list2 := ""
fnb1 := fnb2 := 0 ; <<<<< added: initialize the counters
Loop %dir1%\%fileMask%
{
If ( A_LoopFileName ~= "~\$")
        continue
    fileList1 .= A_LoopFileName . "`n"
    fnb1++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList1, fileList1, 1
Loop %dir2%\%fileMask%
{
    If ( A_LoopFileName ~= "~\$")
        continue
    fileList2 .= A_LoopFileName . "`n"
    fnb2++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList2, fileList2, 1

If (fnb1 = 0) && (fnb2 = 0) ; <<<<< added: early return
    Return

Sort fileList1
Sort fileList2
StringSplit files_1_, fileList1, `n
StringSplit files_2_, fileList2, `n
idxF1 := idxF2 := 1

Loop
{
    If (idxF1 > fnb1) ; <<<<< moved to the top of the loop
    {
        Loop % fnb2 - idxF2 + 1
        {
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Break
    }
    If (idxF2 > fnb2) ; <<<<< moved to the top of the loop
    {
        Loop % fnb1 - idxF1 + 1
        {
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
        Break
    }
    If (files_1_%idxF1% = files_2_%idxF2%)
    {
        ; We are in synch
        list1 .= files_1_%idxF1% . "|"
        idxF1++
        list2 .= files_2_%idxF2% . "|"
        idxF2++
    }
    Else
    {
        ; Either file at idxF1 or at idxF3 is missing, we must find which one
        If (files_1_%idxF1% > files_2_%idxF2%)
        {
            ; Missing in first list
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Else
        {
            ; Missing in second list
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
    }
}
StringTrimRight list1, list1, 1
StringTrimRight list2, list2, 1
Return
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Show for compare fileList1 and fileList2

02 May 2018, 06:06

Hi, just me :superhappy:
All thanks and appreciation to you
You saved me a lot of time and effort
Thank you very much, :thumbup:
and Tnanks for Members of this wonderful forum
Last edited by asad41163 on 02 May 2018, 06:55, edited 2 times in total.
just me
Posts: 7401
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Show for compare fileList1 and fileList2

02 May 2018, 06:33

I don't understand what you mean.
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Show for compare fileList1 and fileList2

02 May 2018, 06:59

That's exactly what I was looking for!
I apologize, and I repeat; thanks very much
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Show for compare fileList1 and fileList2

03 May 2018, 08:59

Hi, just me
This is the final code that you have modified,

Code: Select all

#SingleInstance, Ignore
gosub, DoTheWork

Gui Add, ListBox, w950 r20 vfiles1, % "Dir1 = " dir1 "| |" list1
Gui Add, ListBox, w950 r20 vfiles2, % "Dir2 = " dir2 "| |" list2


Gui Add, Button, w75 gGuiOK default, Exit
;Gui Add, Button, x+30 w75 gGuiClose, Cancel
Gui,Add, Text, yp+5 x200,Dir1
Gui,Add, Edit, yp-3 x230 w300 vDir1,%dir1%
Gui,Add, Text, yp+2 x540,Dir2
Gui,Add, Edit, yp-3 x570 w300 vDir2,%dir2%
Gui,Add, Text, yp+2 x880,Mask
Gui,Add, Edit, yp-3 x910 w60 vFileMask,%fileMask%
Gui Add, Button, yp x980 w75 gGo, Go
Gui Show, w1070
Return

Go:
    Gui, Submit, NoHide 
    gosub, DoTheWork
    GuiControl,,files1,% "|Dir1 = " dir1 "| |" list1
    GuiControl,,files2,% "|Dir2 = " dir2 "| |" list2
return

GuiOK:
GuiClose:
GuiEscape:
ExitApp

DoTheWork:
filelist1 := filelist2 := ""
list1 := list2 := ""
fnb1 := fnb2 := 0 ; <<<<< added: initialize the counters
Loop %dir1%\%fileMask%
{
If ( A_LoopFileName ~= "~\$")
        continue
    fileList1 .= A_LoopFileName . "`n"
    fnb1++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList1, fileList1, 1
Loop %dir2%\%fileMask%
{
    If ( A_LoopFileName ~= "~\$")
        continue
    fileList2 .= A_LoopFileName . "`n"
    fnb2++ ; <<<<< changed: don't use A_Index because some files may be skipped
}
StringTrimRight fileList2, fileList2, 1

If (fnb1 = 0) && (fnb2 = 0) ; <<<<< added: early return
    Return

Sort fileList1
Sort fileList2
StringSplit files_1_, fileList1, `n
StringSplit files_2_, fileList2, `n
idxF1 := idxF2 := 1

Loop
{
    If (idxF1 > fnb1) ; <<<<< moved to the top of the loop
    {
        Loop % fnb2 - idxF2 + 1
        {
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Break
    }
    If (idxF2 > fnb2) ; <<<<< moved to the top of the loop
    {
        Loop % fnb1 - idxF1 + 1
        {
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
        Break
    }
    If (files_1_%idxF1% = files_2_%idxF2%)
    {
        ; We are in synch
        list1 .= files_1_%idxF1% . "|"
        idxF1++
        list2 .= files_2_%idxF2% . "|"
        idxF2++
    }
    Else
    {
        ; Either file at idxF1 or at idxF3 is missing, we must find which one
        If (files_1_%idxF1% > files_2_%idxF2%)
        {
            ; Missing in first list
            list1 .= " |"   ; Empty
            list2 .= files_2_%idxF2% . "|"
            idxF2++
        }
        Else
        {
            ; Missing in second list
            list1 .= files_1_%idxF1% . "|"
            idxF1++
            list2 .= " |"   ; Empty
        }
    }
}
StringTrimRight list1, list1, 1
StringTrimRight list2, list2, 1
Return


#IfWinActive, Comparison
$1::
ControlSetText, Edit1, E:\ask\work
ControlSetText, Edit2, E:\ask\backup
ControlSetText, Edit3, *.docx
ControlClick, Go, Comparison  
return
;;---------------------------------------------------  2

$2::
ControlSetText, Edit1, E:\ask\sales
ControlSetText, Edit2, E:\ask\work
ControlSetText, Edit3, *.pdf
ControlClick, Go, Comparison  
return
;;---------------------------------------------------  3

$3::
ControlSetText, Edit1, E:\ask\sales
ControlSetText, Edit2, E:\ask\backup
ControlSetText, Edit3, *.txt
ControlClick, Go, Comparison  
return
Allow me the last question
In this script I have 3 hotkeys, each hotkey fills the text boxes with predefined data:
- dir 1
- dir 2
- mask (Type of files)
- click go
my question is:
How can I place three buttons instead of three hotkeys
As the picture appears attached.
3 hotkey.png
3 hotkey.png (11 KiB) Viewed 803 times
Well worth the appreciation and thanks for the quick response

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, aifritz, Google [Bot], mikeyww, WOlfen, zuzu_kuc and 49 guests