Jump to content

Compare2Folders


ripdad
 Share

Recommended Posts

; Compare2Folders
; March 06, 2011
#include <GuiListView.au3>
;
Opt("TrayAutoPause", 0)
;
Local $d1, $d2, $nMsg
Local $ui = GUICreate(' Compare2Folders v1.0', 300, 160, -1, -1)
Local $lb = GUICtrlCreateLabel('Select Folders to Compare', 15, 20, 300, 20)
Local $e1 = GUICtrlCreateInput('', 15, 50, 225, 20)
Local $e2 = GUICtrlCreateInput('', 15, 80, 225, 20)
Local $b1 = GUICtrlCreateButton('1', 250, 50, 36, 20)
Local $b2 = GUICtrlCreateButton('2', 250, 80, 36, 20)
Local $b3 = GUICtrlCreateButton('Compare', 110, 120, 70, 20)
;
GUISetState(@SW_SHOW, $ui)
;
Do
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $b1
            GUICtrlSetData($e1, '')
            $d1 = FileSelectFolder('Choose Folder then Click Ok', '', 2, '')
            If $d1 And FileExists($d1) Then GUICtrlSetData($e1, $d1)
        Case $b2
            GUICtrlSetData($e2, '')
            $d2 = FileSelectFolder('Choose Folder then Click Ok', '', 2, '')
            If $d2 And FileExists($d2) Then GUICtrlSetData($e2, $d2)
        Case $b3
            If (Not $d1) Or (Not $d2) Then ContinueLoop
            GUISetState(@SW_HIDE, $ui)
            _Compare($d1, $d2)
    EndSwitch
Until $nMsg = -3
GUIDelete($ui)
Exit
;
; Terms Explaination:
;
; File In Use = File Not Found in Compared Folder. Reason: File In Use
;  Difference = Both Files Exist but Size Difference Between the Two
;   Not Found = Source File Exist but Not in Compared Folder
;
Func _Compare($f1, $f2)
    Local $aRtn = _RecFileFinder($f1, $f2)
    If @error Then
        MsgBox(8208, ' Compare2Folders', $aRtn)
        GUISetState(@SW_SHOW, $ui)
        Return
    ElseIf Not IsArray($aRtn) Then
        MsgBox(8256, ' Compare2Folders', 'No Difference Found ')
        GUISetState(@SW_SHOW, $ui)
        Return
    EndIf
    Local $li = GUICreate(' Compare2Folders v1.0 - Differences Found', 800, 510, -1, -1)
    Local $lv = GUICtrlCreateListView("Path and Filename", 5, 5, 790, 500)
    For $i = 1 To $aRtn[0]
        GUICtrlCreateListViewItem($aRtn[$i], $lv)
    Next
    _GUICtrlListView_SetColumnWidth($lv, 0, $lvSCW_AUTOSIZE)
    GUISetState(@SW_SHOW, $li)
    Do
    Until GUIGetMsg() = -3
    GUIDelete($li)
    GUISetState(@SW_SHOW, $ui)
EndFunc
;
Func SetWidth($num)
    Local $string = ''
    For $n = 1 To $num
        $string &= ' '
    Next
    Return $string
EndFunc
;
; UDF: _RecFileFinder, Author: Melba23
; Modified: March 06, 2011 by ripdad
Func _RecFileFinder($stPath, $cpPath)
    If Not FileExists($stPath) Then Return SetError(-1, 0, 'Path Not Found')
    If StringRight($stPath, 1) <> '\' Then $stPath &= '\'
    If StringRight($cpPath, 1) <> '\' Then $cpPath &= '\'
    Local $asFolderList[3] = [1]
    Local $string, $ttPath, $cPath, $sName, $test
    Local $hSearch, $rPath, $width = SetWidth(70)
    $asFolderList[1] = $stPath
    While $asFolderList[0] > 0
        $cPath = $asFolderList[$asFolderList[0]]
        $ttPath = $cPath
        If StringLen($ttPath) > 60 Then $ttPath = StringTrimRight($ttPath, StringLen($ttPath) - 60)
        ToolTip($ttPath, 0, 0, ' Comparing Folders ' & $width, 1)
        $asFolderList[0] -= 1
        $hSearch = FileFindFirstFile($cPath & '*')
        If $hSearch = -1 Then ContinueLoop
        While 1
            $sName = FileFindNextFile($hSearch)
            If @error Then ExitLoop
            If @extended Then
                $asFolderList[0] += 1
                If UBound($asFolderList) <= $asFolderList[0] + 1 Then ReDim $asFolderList[UBound($asFolderList) * 2]
                $asFolderList[$asFolderList[0]] = $cPath & $sName & '\'
                ContinueLoop
            EndIf
            $rPath = StringReplace($cPath, $stPath, $cpPath)
            If Not FileExists($rPath & $sName) Then
                 $test = FileOpen($cPath & $sName)
                 If $test = -1 Then
                     $string &= 'File In Use --> ' & $cPath & $sName & '|'
                 Else
                     $string &= 'Not Found --> ' & $rPath & $sName & '|'
                     FileClose($test)
                 EndIf
                 $test = ''
                 ContinueLoop
            EndIf
            If FileGetSize($cPath & $sName) <> FileGetSize($rPath & $sName) Then
                $string &= 'Difference --> ' & $cPath & $sName & '|'
            EndIf
        WEnd
        FileClose($hSearch)
    WEnd
    ToolTip('')
    If Not $string Then Return SetError(0, 0, '')
    Local $sa = StringSplit(StringTrimRight($string, 1), '|')
    _ArraySort($sa, 0, 1)
    Return SetError(0, 0, $sa)
EndFunc
;

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Thanks ... and thank-you Melba23 for your _RecFileFinder. I use it quite alot.

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...