comparison script

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

comparison script

17 Feb 2018, 04:27

hi, guys
this code for A folder comparison script
it's from here:
https://autohotkey.com/board/topic/1617 ... on-script/

Code: Select all

dir1 = D:\work
dir2 = E:\Backup
fileMask = *.docx

Loop %dir1%\%fileMask%
{
	fileList1 .= A_LoopFileName . "`n"
	fnb1 := A_Index
}
StringTrimRight fileList1, fileList1, 1

Loop %dir2%\%fileMask%
{
	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
Gui Add, ListBox, w200 r20 vfiles1, %list1%
StringTrimRight list2, list2, 1
Gui Add, ListBox, x+20 w200 r20 vfiles2, %list2%

Gui Add, Button, w50 gGuiOK default, OK
Gui Add, Button, x+50 w50 gGuiClose, Cancel
Gui Show, w500
Return

GuiOK:
GuiClose:
GuiEscape:
ExitApp
it's works very good.
My question is: How to put the folder name at the top of the window.
So: dir1 = D:\work
dir2 = E:\Backup
and, How to make files that start with this tag do not appear.
So: ~$normal.dotm.
As is evident from the picture.
Thanks in advance.
Pic Final.png
Pic Final.png (14.91 KiB) Viewed 1678 times
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: comparison script

17 Feb 2018, 05:02

Put in the first two loops this:

Code: Select all

If ( A_LoopFileName = "~$normal.dotm")
        continue
And in the Gui definition this:

Code: Select all

Gui Add, ListBox, w200 r20 vfiles1, % "Dir1 = " dir1 "| |" list1
;...
Gui Add, ListBox, x+20 w200 r20 vfiles2, % "Dir2 = " dir2 "| |" list2
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: comparison script

17 Feb 2018, 07:16

Oh Mr. Odlanir - that's great!
That's exactly what I was looking for!
Much appreciated and I've learnt lots
But the problem is that these types of files: "~$normal.dotm"
It has very very many names, it is only united in the file extension
But their names are more than 100 names.
I tried to use this expression "~$*.dotm" but failed.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: comparison script

17 Feb 2018, 07:23

Code: Select all

	If ( RegExMatch(A_LoopFileName, "~\$"))
        continue
;---or
	If ( A_LoopFileName ~= "~\$")
        continue
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: comparison script

17 Feb 2018, 07:37

hi Mr. Odlanir,
Well worth the appreciation and thanks for the quick response
I'll try, then come back immediately
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: comparison script

17 Feb 2018, 07:52

Mr. Odlanir
All thanks and appreciation to you
You saved me a lot of time and effort
Thank you very much,
and Tnanks for Members of this wonderful forum
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: comparison script

21 Feb 2018, 13:30

hi, Odlanir
All thanks and appreciation to you for all help

this is the final code:

Code: Select all

dir1 = E:\work
dir2 = D:\all
fileMask = *.docx



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
; Gui Add, ListBox, w1200 r20 vfiles1, %list1%
Gui Add, ListBox, w1200 r20 vfiles1, % "Dir1 = " dir1 "| |" list1
;...

StringTrimRight list2, list2, 1
; Gui Add, ListBox, x+20 w200 r20 vfiles2, %list2%
Gui Add, ListBox, w1200 r20 vfiles2, % "Dir2 = " dir2 "| |" list2


Gui Add, Button, w50 gGuiOK default, OK
Gui Add, Button, x+50 w50 gGuiClose, Cancel
Gui Show, w1200
Return


GuiOK:
GuiClose:
GuiEscape:
ExitApp
my question is: Is it possible the code take the File extension same as (*.docx) from inputbox, and the path from dialog box by the user:
I mean this part:

Code: Select all

dir1 = D:\re
dir2 = D:\all
fileMask = *.docx
I am very grateful to you, and please show me how to do it.
Thanks in advance.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: comparison script

21 Feb 2018, 14:25

Try this:

Code: Select all

dir1 := "E:\work"
dir2 := "D:\all"
fileMask := "*.docx"
gosub, DoTheWork

Gui Add, ListBox, w1200 r10 vfiles1, % "Dir1 = " dir1 "| |" list1
Gui Add, ListBox, w1200 r10 vfiles2, % "Dir2 = " dir2 "| |" list2
Gui Add, Button, w50 gGuiOK default, OK
Gui Add, Button, x+50 w50 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 w50 vFileMask,%fileMask%
Gui Add, Button, yp x1000 w100 gGo, Go
Gui Show, w1200
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
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: comparison script

22 Feb 2018, 02:05

hi, Odlanir
You are really wonderful and distinct, and have taught me a lot
Thank you so much
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: comparison script

07 Mar 2018, 08:36

Hi, Odlanir
This is the final code that you have modified,

Code: Select all

dir1 := ""
dir2 := ""
fileMask := ""
gosub, DoTheWork

Gui Add, ListBox, w1200 r10 vfiles1, % "Dir1 = " dir1 "| |" list1
Gui Add, ListBox, w1200 r10 vfiles2, % "Dir2 = " dir2 "| |" list2
Gui Add, Button, w50 gGuiOK default, OK
Gui Add, Button, x+50 w50 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 w50 vFileMask,%fileMask%
Gui Add, Button, yp x1000 w100 gGo, Go
Gui Show, w1200
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
I have added this part to it:

Code: Select all

SetTitleMatchMode, 1
#IfWinActive, compare.ahk

F2::
ControlSend, Edit1, c:\
ControlSend, Edit2, d:\
ControlSend, Edit3, *.pdf
ControlClick, Go, compare.ahk  ; Clicks the OK button
return

#IfWinActive, compare.ahk
F3::
ControlSend, Edit1, \\srv\Al-Motahida\Projects\IACPA\IACPA\SB
ControlSend, Edit2, \\srv\Al-Motahida\Projects\IACPA\IACPA\U1
ControlSend, Edit3, *.docx
ControlClick, Go, compare.ahk  ; Clicks the OK button
return
Mr. Odlanir
Please. allow me a last question:
Is there a way to modify the script to copy, open, or open file location?
thanks in advance
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: comparison script

08 Mar 2018, 06:32

Hi all,
Is there a way to modify the script to copy, open, or open file location?
thanks in advance

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, boiler, malcev, tee_rock and 133 guests