Compare Folders is a free and easy to use application that will help you compare the contents of two folders, with or without extensions. Unfortunately, right when you discover a nice working tool, you also see that it does not support the inclusion of subfolders in the comparison – you cannot compare directory trees, only a pair of folders each time. Features: Compare the files in a folder by their names and extensions, or just by their names * Files that only occur in one folder get a check in their checkboxes * Checked files can be copied to the other folder * Checked files can be deleted (To the recycling bin) Compare Folders is not in active development.
This wikiHow teaches you how to compare the contents and total sizes of two folders using the Windows File Explorer.
wikiHow Technology Writer This article was written by Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 86,966 times.
Co-authors: 2 Updated: September 6, 2019 Views: 86,966 Categories: Windows Files
Thanks to all authors for creating a page that has been read 86,966 times.
I am trying to do something along the lines of: diff `ls -1a ./dir1` `ls -1a ./dir2`But that doesn't work for obvious reasons. Is there a better way of achieving this (in 1 line), than this? ls -1a ./dir1 > lsdir1 ls -1a ./dir2 > lsdir2 diff lsdir1 lsdir2Thanks
Hi Oscar, This is really a nice piece of coding! I want to add the column "filedatetime" to have a complete comparison (filelen 'could' be the same, but the newest file would have the benefit. I am not sure where to adapt the array redim's: Sub CompareContentsofTwoFolders() Dim pth1 As String, pth2 As String Dim r1 As Single, r2 As Single Dim arrd() As Variant Dim arru() As Variant 'Redims changed ReDim arrd(0 To 8, 0) ReDim arru(0 To 6, 0) 'Ask for first folder (path) pth1 = "Z:\sync\newsync\USB Profile #4\" 'Ask for second folder (path) pth2 = "Z:\sync\oldsync\USB Profile #4\" 'Insert a new sheet Sheets.Add Set x = ActiveSheet 'Get a list of first folder´s content to a sheet Application.ScreenUpdating = False x.Range("A1") = "Duplicate files" x.Range("A2") = "Path" x.Range("B2") = "File name" x.Range("C2") = "Size" 'here datstamp added x.Range("D2") = "Datestamp" x.Range("E2") = "Path" x.Range("F2") = "File name" x.Range("G2") = "Size" x.Range("H2") = "Datestamp" x.Range("A:H").Font.Bold = False x.Range("A1:H2").Font.Bold = True Recursive pth1 'Sort list and then move it to an array lrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row x.Range("A2:D" & lrow).Sort Key1:=x.Range("B1"), Header:=xlYes 'Move range to array arr1 = x.Range("A3:D" & lrow).Value 'Clear contents on sheet x.Range("A3:D" & lrow).Clear 'Get a list of the second of folder and save it to an array Recursive pth2 'Sort list and then move it to an array lrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row x.Range("A2:D" & lrow).Sort Key1:=x.Range("B1"), Header:=xlYes 'Move range to array arr2 = x.Range("A3:D" & lrow).Value 'Clear contents on sheet x.Range("A3:D" & lrow).Clear 'Loop files in first folder For r1 = LBound(arr1, 1) To UBound(arr1, 1) chk = False 'First value in array? If r1 > 1 Then 'Check if value is equal to previous value If arr1(r1, 2) = arr1(r1 - 1, 2) Then 'Find the last value in dupes array arrd(?,2) For r3 = UBound(arrd, 2) To LBound(arrd, 2) Step -1 If arrd(2, r3) <> "" And arrd(1, r3) <> arr1(r1, 2) Then Exit For If arrd(1, r3) = arr1(r1, 2) Then If r3 = UBound(arrd, 2) Then ReDim Preserve arrd(UBound(arrd, 1), UBound(arrd, 2) + 1) arrd(0, r3 + 1) = arr1(r1, 1) arrd(1, r3 + 1) = arr1(r1, 2) arrd(2, r3 + 1) = arr1(r1, 3) arrd(3, r3 + 1) = arr1(r1, 4) ReDim Preserve arrd(UBound(arrd, 1), UBound(arrd, 2) + 1) Exit For End If Next r3 'Find the last value in uniques array arru(?,2) For r3 = UBound(arru, 2) To LBound(arru, 2) Step -1 If arru(2, r3) <> "" And arru(1, r3) <> arr1(r1, 2) Then Exit For If arru(1, r3) = arr1(r1, 2) Then If r3 = UBound(arru, 2) Then ReDim Preserve arru(UBound(arru, 1), UBound(arru, 2) + 1) arru(0, r3 + 1) = arr1(r1, 1) arru(1, r3 + 1) = arr1(r1, 2) arru(2, r3 + 1) = arr1(r1, 3) '******************************** HERE IT GOES WRONG arru(3, r3 + 1) = arr1(r1, 4) ReDim Preserve arru(UBound(arru, 1), UBound(arru, 3) + 1) '******************************** It is not clear to me how to resize the array in a proper way? Exit For End If Next r3 GoTo jmp End If End If 'Loop files in second folder For r2 = LBound(arr2, 1) To UBound(arr2, 1) 'Check if values are equal If arr2(r2, 2) = arr1(r1, 2) Then 'First match in arr2 If chk = False Then arrd(0, UBound(arrd, 2)) = arr1(r1, 1) arrd(1, UBound(arrd, 2)) = arr1(r1, 2) arrd(2, UBound(arrd, 2)) = arr1(r1, 3) arrd(3, UBound(arrd, 2)) = arr1(r1, 4) 'There are previous matches in arr2 Else arrd(0, UBound(arrd, 2)) = "" arrd(1, UBound(arrd, 2)) = "" arrd(2, UBound(arrd, 2)) = "" arrd(3, UBound(arrd, 2)) = "" End If 'Save arr2 in dupes array arrd arrd(4, UBound(arrd, 2)) = arr2(r2, 1) arrd(5, UBound(arrd, 2)) = arr2(r2, 2) arrd(6, UBound(arrd, 2)) = arr2(r2, 3) arrd(7, UBound(arrd, 2)) = arr2(r2, 4) 'Delete first value in arr2 arr2(r2, 1) = "" 'arr2(r2, 2) = "" 'arr2(r2, 3) = "" ReDim Preserve arrd(UBound(arrd, 1), UBound(arrd, 2) + 1) chk = True End If Next r2 'No match, save arr1 values to uniques array arru If chk = False Then arru(0, UBound(arru, 2)) = arr1(r1, 1) arru(1, UBound(arru, 2)) = arr1(r1, 2) arru(2, UBound(arru, 2)) = arr1(r1, 3) arru(3, UBound(arru, 2)) = arr1(r1, 4) ReDim Preserve arru(UBound(arru, 1), UBound(arru, 2) + 1) End If jmp: Next r1 'Add unique values in arr2 (non empty values) to arru For r2 = LBound(arr2, 1) To UBound(arr2, 1) If arr2(r2, 1) <> "" Then arru(0, UBound(arru, 2)) = arr2(r2, 1) arru(1, UBound(arru, 2)) = arr2(r2, 2) arru(2, UBound(arru, 2)) = arr2(r2, 3) arru(3, UBound(arru, 2)) = arr1(r1, 4) ReDim Preserve arru(UBound(arru, 1), UBound(arru, 2) + 1) End If Next r2 'Return values to sheet x.Range("A3").Resize(UBound(arrd, 2) + 1, UBound(arrd, 1) + 1) = Application.Transpose(arrd) x.Range("A" & UBound(arrd, 2) + 3) = "Unique files" x.Range("A" & UBound(arrd, 2) + 4) = "Path" x.Range("B" & UBound(arrd, 2) + 4) = "File name" x.Range("C" & UBound(arrd, 2) + 4) = "Size" x.Range("D" & UBound(arrd, 2) + 4) = "Datestamp" x.Range("A" & UBound(arrd, 2) + 3 & ":C" & UBound(arrd, 2) + 4).Font.Bold = True x.Range("A" & UBound(arrd, 2) + 5).Resize(UBound(arru, 2) + 1, UBound(arru, 1) + 1) = Application.Transpose(arru) 'Autofit cell width x.Columns("A:G").AutoFit Application.ScreenUpdating = True End Sub Sub Recursive(FolderPath As String) Dim Value As String, Folders() As String Dim Folder As Variant, a As Long ReDim Folders(0) If Right(FolderPath, 2) = "\\" Then Exit Sub Value = Dir(FolderPath, &H1F) Do Until Value = "" If Value = "." Or Value = ".." Then Else If GetAttr(FolderPath & Value) = 16 Or GetAttr(FolderPath & Value) = 48 Then Folders(UBound(Folders)) = Value ReDim Preserve Folders(UBound(Folders) + 1) Else lrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row + 1 ActiveSheet.Range("A" & lrow) = FolderPath ActiveSheet.Range("B" & lrow) = Value ActiveSheet.Range("C" & lrow) = FileLen(FolderPath & Value) ActiveSheet.Range("D" & lrow) = FileDateTime(FolderPath & Value) End If End If Value = Dir Loop For Each Folder In Folders Recursive FolderPath & Folder & "\" Next Folder End SubI would very, very much appreciate the help. Johan |