AutoHotkey Community

It is currently May 27th, 2012, 9:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Directory Compare
PostPosted: October 21st, 2006, 5:05 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
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.

Update1: I discovered that when comparing files on two drives with different cluster sizes, the size reported for identical files will be slightly different between the two. To solve this, I incorporated a ratio into the comparison procedure, so that files with identical names and almost identical sizes are considered equal.

    ● Several minor changes were also made: most notably, files with unique sizes are now separated from files with unique names in the final list view (unique sizes come first).
Update2: I've created a new GUI frontend for the program, with support for drag-and-drop.

    ● It now has error checking.
Here is the newest script: >DOWNLOAD<

Image


Last edited by jaco0646 on June 22nd, 2009, 6:52 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 8:10 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear jaco0646, :)

Nice! :D ..

Quote:
This has only been tested on WinXP. For another OS, the "Static9" control will likely be something else


The script runs fine in Windows 2000.

I compared between AutoHotkey versions 1.0.44.00 & 1.0.44.13.
Here is a snapshot: http://autohotkey.net/~goyyah/samples/d ... ompare.png

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Directory Compare
PostPosted: October 21st, 2006, 12:35 pm 
I try in XP Pro:
jaco0646 wrote:
path1 = C:\LP\
path2 = D:\Backup\LP\

But doing nothing, whats wrong please?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 1:17 pm 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
Quote:
path1 = C:\LP\
path2 = D:\Backup\LP\

But doing nothing, whats wrong please?

I've added basic directory checking to this version. The original gives no warning if the paths are not exactly correct.

Code:
#SingleInstance force
#NoTrayIcon
;__________________________________________________________
path1 = ;<-- Enter a folder path here
path2 = ;<-- Enter a second folder path here
;__________________________________________________________

; Check if paths exists, if not - warn.
FileGetAttrib, attrib, %path1%
IfNotInString, attrib, D
  {
    MsgBox, 4096, Warning, Could not open: %path1%, 30
    Return
  }
FileGetAttrib, attrib, %path2%
IfNotInString, attrib, D
  {
    MsgBox, 4096, Warning, Could not open: %path2%, 30
    Return
  }

Gui, Add, ListView, w640 h400 Grid
        , %path1%|Size(KB)|%path2%|Size(KB)
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.
    ExitApp
  }
LV_ModifyCol()
LV_ModifyCol(2, "Float")
LV_ModifyCol(4, "Float")
Gui, Show,, Directory Compare
Return
GuiClose:
  ExitApp
  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)
      }
  }

_________________
ChrisM


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 3:14 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
@ Directory:
You don't need to add the final backslash: " \ " to the paths. The script already does that for you. I didn't think to mention that before, but removing those should correct the problem.
Code:
path1 = C:\LP
path2 = D:\Backup\LP


@ ChrisM
Directory checking is a good idea. The only reason I didn't add it is that I always compare the same two folders and rarely any others. Perhaps the best method would be to add two FileSelectFolder commands for picking the directories. This would ensure that there are no trailing backslashes as well, eliminating the problem that Directory encountered.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 4:28 pm 
jaco0646 wrote:
@ Directory:
You don't need to add the final backslash: " \ " to the paths. The script already does that for you. I didn't think to mention that before, but removing those should correct the problem.
Code:
path1 = C:\LP
path2 = D:\Backup\LP

Thank you, but I was try with and without " \ ", same thing with the add of ChrisM (Tank you too)
maybe is my sistem problem... :oops:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2006, 10:14 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
I can't think of what the problem could be. If you don't see anything after running the script, it might be stuck in the count() function at WinWait, or in the loop thereafter. You could try limiting the loop to a number of iterations and see if that helps.

If you do find a solution, please post it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2006, 12:49 pm 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
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
  }

_________________
ChrisM


Last edited by ChrisM on October 22nd, 2006, 10:19 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2006, 9:58 pm 
Offline

Joined: November 28th, 2004, 10:26 pm
Posts: 58
The above code was just edited to fix a bug that wasn't storing the ini file to the same dir as the script.

_________________
ChrisM


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2009, 5:07 am 
I know it is a VERY old post, but jaco, can you update this with the option to copy missing folder between a directory automatically?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 6th, 2009, 6:38 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
I probably won't get time to do anything with it this weekend, but I'll see if the mood strikes me next week. In the meantime, have you seen Microsoft's free SyncToy v2.0?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2009, 4:29 pm 
Offline

Joined: June 17th, 2008, 7:51 am
Posts: 243
Anonymous wrote:
I know it is a VERY old post, but jaco, can you update this with the option to copy missing folder between a directory automatically?
Have you ever tried TotalCommander? http://www.ghisler.com/index.htm

_________________
Greetings
Rog


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 18th, 2009, 2:38 pm 
Thanks guys, I will try those


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group