Results 1 to 6 of 6

Thread: Best method of comparing changes to directories or hives

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Best method of comparing changes to directories or hives

    i can can easily compare for added or changed values,
    loop through newer list and match against the previous, but while this shows items added, it does not show items removed,

    is there a better solution to having to loop through the older list as well to find removed items?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Best method of comparing changes to directories or hives

    Pete

    Wouldn't removed items appear in the Recycle Bin?

    Not sure how that would help, though, since looping
    through that list would be equivalent to (or worse than)
    looping through your "older list".

    Spoo

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best method of comparing changes to directories or hives

    Wouldn't removed items appear in the Recycle Bin?
    certainly no guarantee of that, files deleted by code do not go to recycle
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Best method of comparing changes to directories or hives

    Pete

    Fair enough.

    Pehaps we can then agree, at least, that your OP was
    somewhat ambiguous. Could you possibly elaborate?

    What is the series of events ...
    • When is the "previous" list created?
    • When is the "newer" list created?
    • What transpires during the interim?
    • How are directories added, changed, or deleted ?
      • By code only
      • By code and manually?
      • Other?

    Spoo

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Best method of comparing changes to directories or hives

    When is the "previous" list created?
    at any time, when required, or may be a current directory, not a list

    When is the "newer" list created?
    probably just before comparing results, but may just be some other current directory

    What transpires during the interim?
    whatever, or nothing

    How are directories added, changed, or deleted ?
    by install, uninstall, manual or code add or delete, effect of someother program, or anything i have not yet thought of

    same question as regarding comparing registry keys
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Best method of comparing changes to directories or hives

    The only thing I can think of is that as you go through the new list you delete matching and changed entries from the old list. What's left in the old list at the end are those items that do not appear in the new list. Saves a complete second pass of the old list. I guess you could use a couple of collections to hold the lists, because it's easy to remove items (perhaps?)

    EDIT: Another way is to sort both lists and compare the values to each other.

    I=0;J=0
    Start Loop:
    compare List1(I) to List2(J)
    if equal then both appear in both lists, inrcement I and J;
    if List1(I) < List2(J) then item is in List2 not List1, increment I,
    if List1(I) > List2(J) then item is in List1 not in List2, increment J.
    Loop until either I > ubound(List1) or J > ubound(List2).

    Then loop through items I to ubound(List1) to show any additional items in List1 that were not in List2. (This caters for List1 having more entries after List2 has been exhausted)
    Then loop through items J to ubound(List2) to show any additional items in List2 that were not in List1. (This caters for List2 having more entries after List1 has been exhausted)

    If both lists have the same number of entries then neither loop will run. Otherwise one (and only one) of them will.

    On second thoughts, it may be easier to show the code:
    Code:
    Option Explicit
    Private strList1(9) As String
    Private strList2(12) As String
    
    Private Sub Command_Click()
    Dim intL1 As Integer
    Dim intL2 As Integer
    Dim intI As Integer
    Do
        Select Case strList1(intL1) - strList2(intL2)
            Case Is = 0
                Debug.Print strList1(intL1); " is in both lists "; strList2(intL2)
                intL1 = intL1 + 1
                intL2 = intL2 + 1
            Case Is < 0
                Debug.Print strList1(intL1); " is in list1 but not in list2"
                intL1 = intL1 + 1
            Case Is > 0
                Debug.Print strList2(intL2); " is in list2 but not list1"
                intL2 = intL2 + 1
        End Select
    Loop Until intL1 > UBound(strList1) Or intL2 > UBound(strList2)
    For intI = intL1 To UBound(strList1)
        Debug.Print strList1(intI); " is in list1 but not list2"
    Next intI
    For intI = intL2 To UBound(strList2)
        Debug.Print strList2(intI); " is in list2 but not in list1"
    Next intI
    End Sub
    
    Private Sub Form_Load()
    Dim intI As Integer
    For intI = 0 To 9
        strList1(intI) = intI
    Next intI
    strList2(0) = 0
    strList2(1) = 1
    For intI = 2 To 12
        strList2(intI) = intI + 1
    Next intI
    End Sub
    (If you don't count the sort, each list is only parsed once)

    I used numbers for values and Select Case 'cause it was easier to demonstrate the logic. I'm sure you can adapt as necessary to suit your requirements. (Obviously, both lists have to be sorted in the same order)

    Takes me back to the old Mainframe Days of Updating data on 2400ft. Mag. Tapes in Batch so it may be a bit rusty and full of cobwebs, but hopefully, by now, the Spiders should have eaten most of the bugs
    Last edited by Doogle; Aug 23rd, 2011 at 01:36 AM. Reason: Few typos, as usual

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width