Jump to content

My Program: Directory Compare


blindwig
 Share

Recommended Posts

I wrote a program to compare the recursive list of files and folders in 2 directories. I originally wrote this to test my _FileFindAllR and _Array1PullCommon UDFs, but ended up writing a new inline comparison routine that would be faster than my original one.

The program has a GUI where you can set all the options, but it also accepts command-line parameters, so you can use it in a BAT file or something. Type DirectoryCompare /? from a command-line for help with command-line switches (or just look at the source, the help string is near the beginning).

I learned something about comparing 2 lists:

There were 2 ways I could think to do it, one would be to sort boths lists and then go line by line and compare them.

The other way would be to sort just 1 list, and then use BinarySearch to compare the unsorted list against the sorted one. The Binary Search would of course be slower, but I was hoping it would off-set the time needed to sort both lists.

Turns out that the 2nd method was about 4x slower than the first, so I went back to that.

Anyway, have a look, tell me what you think.

BTW, does anyone know how to write out to the console? So like if you called this program from a command-line, I could write message out to the console instead of in messageboxes?

And what's the secrect to getting a screenshot to appear in a post? I can't seem to get this to work...

edit: I removed the original attachments

Edited by blindwig
Link to comment
Share on other sites

  • 2 weeks later...
Link to comment
Share on other sites

I compressed them with Maximum compression, and there is a note that says that some older ZIP routines don't recognize this method. Try WinZip, that's what I'm using and it works. So does my copy of WinRar, v 3.42 (unregistered)

Link to comment
Share on other sites

Here's a screenshot. I tried adding this before but it wouldn't work. I just figured out that my allotment for attachment space on this board was all used up!

Link to comment
Share on other sites

>Running: (3.1.1.56):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Documents and Settings\Gary\My Documents\Projects\DirectoryCompare\DirectoryCompare.au3"   

C:\Documents and Settings\Gary\My Documents\Projects\DirectoryCompare\DirectoryCompare.au3 (235) : ==> Subscript used with non-Array variable.:

$FinalReport[$FinalReport[0][0]][0] = $DirList1ptr[$DirList1ptr]

$FinalReport[$FinalReport[0][0]][0] = $DirList1ptr^ ERROR

>AutoIT3.exe ended.

Shoud be $DirList1[$DirList1ptr] Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

So far I like it, might come in handy

been playing around with viewing the report, currently playing around with the RichText control, going to see what other controls might work good for that.

If $Interactive Then _PreviewFile($gReportFile)

Func _PreviewFile($s_file)
    
    $oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")
    
    $GUI = GUICreate("Directory Compare Results", 500, 500, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_VISIBLE, $WS_CLIPSIBLINGS))
    
    $GUIActiveX = GUICtrlCreateObj($oRP, 10, 10, 480, 480)
    GUICtrlSetPos($GUIActiveX, 10, 10, 480, 470)
    $LinkoRP = ObjEvent($oRP, "IEEvent_", "FolderView"); this is a dummy event handle
    
    With $oRP; Object tag pool
        .OLEDrag ()
        .SelBullet = True
        If FileExists($s_file) Then .LoadFile ($s_file, 1)
        .Enabled = True
        .HideSelection = False
        .SelFontSize = 8
    EndWith
    
    GUISetState();Show GUI
    
    While 1
        $msg = GUIGetMsg()
        
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect
    WEnd
    
    GUIDelete($GUI)
    
EndFunc  ;==>_PreviewFile

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thank for pointing that out - I don't know how I missed it. I guess in all my tests, Dir1 was always smaller than Dir2.

I also added a feature I forgot to document - you can have multiple file masks, seperated by semi-colon. For example: '*.exe;*.dll;*.zip'

But you know, just thinking about that - there is no check that a file matches multiple masks. For example, if you set the mask to '*.exe;a*.*', then AnyThing.Exe would show up twice in the report. Hmm... I'll have to think about that...

Oh, and another bug in DoCompare() - notice that after WriteReport() I check @Error, but first I call TimerDiff, so @error gets destroyed. Need to use $Error like I did with DirectoryCompare()

Oh, and I like your _PreviewFile function. I didn't know of a way to use a RichText box in AutoIt. I have a function I wrote, called _StringBox, for displaying strings that are just too big and/or obnoxious for MsgBox. Right now it uses an EditBox control, which has the 64KB limitation. I'll use your technique to change that to a RichTextBox.

Link to comment
Share on other sites

If i were you i'd check the About button and carefully read how you spelled your own creation :)))

Think u'll find what i mean with this little hint :evil:

<{POST_SNAPBACK}>

Thanks for the report. Technically the problem isn't in the about box, it's in the $AppName assignment on line 7 of DirectoryCompare.au3
Link to comment
Share on other sites

  • 2 months later...

OK, I updated my Directory Compare Program to use my multi-level progress bars. Still don't have a cancel button though, that's next...

Downloaded the code and tested it against the folders

C:\temp\test\

C:\temp\test-foo\

This triggers a wrong descission in

MsgBox(1,"Test", Func _FileDirIsDecendant("C:\temp\test\", "C:\temp\test-foo\"))

Modifying _FileGetTruePath to

Func _FileGetTruePath($sPath)
    Dim $LastDir = @WorkingDir, $Return
    If FileChangeDir($sPath) Then
    ;@WorkingDir does not return with a delimiter \ as the last char
        $Return = @WorkingDir & "\"
        FileChangeDir($LastDir)
    Else
        _DebugPrint("ERROR: FileChangedir(" & $sPath & ") failed")
        SetError(1)
        $Return = ''
    EndIf
    Return $Return
EndFunc  ;==>_FileGetTruePath

Will do the trick to get comparing started but there is issues further down the line

C:\temp\autoit\DirectoryCompare\DirectoryCompare.au3 (238) : ==> Subscript used with non-Array variable.:

$FinalReport[$FinalReport[0][0]][0] = $DirList1ptr[$DirList1ptr]

$FinalReport[$FinalReport[0][0]][0] = $DirList1ptr^ ERROR

C:\temp\autoit\DirectoryCompare\DirectoryCompare.au3 (570) : ==> Error in expression.:

Local $aReport = DirectoryCompare($gDir1, $gDir2, $gCompareFlags, $gFileMask, $gAttribFilter)

Local $aReport = ^ ERROR

Not shure if this is fixed somwhere.

Regards

Uten

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...