Results 1 to 3 of 3

Thread: Compare folder contents

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Compare folder contents

    Guys,

    I have 2 folders. How can I compare the contents, including sub-folders, and show the number of common files and total file count? I have a software build that should span 3 disks but I have a feeling that they have burnt disk 1 3 times and labelled incorrectly!!! Its hard to drill down as the folders get quite deep, everything looks the same so far.

    Can anybody help me with a quick sub to loop thru and compare the folder structure and contents, please?

    Thanks
    Bob
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: Compare folder contents

    The WinMerge utility in my signature supports that function, maybe that will save you some coding.

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Compare folder contents

    vb Code:
    1. Public Sub CompareFiles(ByVal directoryName As String)
    2.         'loop through files to see which are missing
    3.         For Each filename As String In IO.Directory.GetFiles(directoryName)
    4.             'replace current drive letter with one to compare to
    5.             Dim fileParts() As String = filename.Split(IO.Path.DirectorySeparatorChar)
    6.             'you could set require this as input to make it dynamic
    7.             fileParts(0) = "D:"
    8.             Dim compareDirectoryName As String = String.Join(IO.Path.DirectorySeparatorChar, fileParts)
    9.             If Not IO.File.Exists(compareDirectoryName) Then
    10.                 'file missing
    11.             End If
    12.         Next
    13.         'loop through sub directories using recursion
    14.         For Each subDirectory As String In IO.Directory.GetDirectories(directoryName)
    15.             CompareFiles(subDirectory)
    16.         Next
    17.     End Sub

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