Here's a version that has file selection built into the GUI. Basic functionality is still the same.
One thing I can't figure out is how to get the FileSelectFolder dialogue to appear in the middle of the page. For me it's always too low and to the right so the ok and cancel buttons are off the screen.
Code:
; This is a script that I use to check whether or not the files from my laptop
; are backed up onto my desktop PC and vice versa. It compares the contents of
; two folders based on file names and sizes. Other comparisons could easily be
; added as well, such as time stamps.
; Simply start the script and type in or select the folders to compare,
; and it will show which files are unique to each.
; This has only been tested on WinXP. For another OS, the "Static9" control
; will likely be something else.
#SingleInstance force
#NoTrayIcon
#NoEnv ; Must have this so path vars below don't resolve to env path.
; Default path start points
path1 =
path2 =
; Read paths in from ini file
SplitPath, A_ScriptFullPath, , dir, , iniFile
iniFile = %dir%\%iniFile%.ini
i = 0
Loop
{
i++
FileReadLine, tmp, %iniFile%, %i%
If ErrorLevel
Break
path%i% := tmp
GuiControl,, path%i%, %tmp%
}
Gui, Add, Edit, x16 y20 w350 h20 vpath1
Gui, Add, Edit, x446 y20 w350 h20 vpath2
Gui, Add, Button, x370 y20 w60 h20 gSelectPath1, Browse
Gui, Add, Button, x800 y20 w60 h20 gSelectPath2, Browse
Gui, Add, Button, x16 y50 w160 h30 gCompareDirs, Compare
Gui, Add, ListView, x16 y90 w840 h540 Grid
, %path1%|Size(KB)|%path2%|Size(KB)
wCol1 = 330
wCol2 = 80
wCol3 = 330
wCol4 = 80
LV_ModifyCol()
LV_ModifyCol(2, "Float")
LV_ModifyCol(4, "Float")
LV_ModifyCol( 1, wCol1)
LV_ModifyCol( 2, wCol2)
LV_ModifyCol( 3, wCol3)
LV_ModifyCol( 4, wCol4)
Gui, Show, x82 y35 h646 w880, Directory Compare
i = 0
Loop, 2
{
i++
tmp := path%i%
GuiControl,, path%i%, %tmp%
}
Return
GuiClose:
ExitApp
Return
SaveToIni()
{
global
; Save paths to ini file
FileDelete, %iniFile%
i = 0
Loop, 2
{
i++
tmp := path%i%
FileAppend, %tmp%`n, %iniFile%
}
}
SelectPath1:
{
path1 := SelectFolder( path1 )
GuiControl,, path1, %path1%
Return
}
SelectPath2:
{
path2 := SelectFolder( path2 )
GuiControl,, path2, %path2%
Return
}
SelectFolder( path )
{
Gui +OwnDialogs
tmp = %path%
FileSelectFolder, path, *%path%, 2
If ErrorLevel
path = %tmp%
CheckDir( path )
Return path
}
CheckDir( path )
{
; Check if paths exists, if not - warn.
FileGetAttrib, attrib, %path%
IfNotInString, attrib, D
{
MsgBox, 4096, Warning, Could not open: %path%, 30
Return 1
}
Return 0
}
CompareDirs:
{
LV_Delete()
LV_ModifyCol( 1, wCol1, path1)
LV_ModifyCol( 3, wCol3, path2)
Gui Submit, NoHide
SaveToIni()
If ( CheckDir( path1 ) )
Return
If ( CheckDir( path2 ) )
Return
Count := Count(path1) + Count(path2)
Progress, fs14 b2 r0-%Count%, Checking files`, please wait.
Compare(path1, path2, 1)
Compare(path2, path1, 3)
Progress, Off
If LV_GetCount() = 0
{
MsgBox, 4160, Equal, All files are backed up.
}
Return
}
Count(path)
{
SetTitleMatchMode, 2
Run, properties %path%, %path%, Hide
WinWait, Properties ahk_class #32770
Loop
{
ControlGetText, Count, static9
If Count !=
Break
}
WinClose
StringGetPos, num, Count, %A_Space%
StringLeft, Count, Count, num
Return, Count
}
Compare(path1, path2, num)
{
static Count
Loop, %path1%\*.*,,1
{
Count++
Progress, %Count%
FileGetSize, size1, %A_LoopFileLongPath%
StringReplace, name, A_LoopFileLongPath, %path1%\
IfExist, %path2%\%name%
{
FileGetSize, size2, %path2%\%name%
If (size1 = size2)
Continue
}
i++
If name Contains \
name = \%name%
SetFormat, Float, 0.2
If (LV_GetCount() < i)
LV_Add("Col" num, name, size1/1024)
Else LV_Modify(i, "Col" num, name, size1/1024)
}
Return
}