Macro to find Dupliacte files in a given folder

Mavericks334

Active Member
Joined
Jan 26, 2011
Messages
280
Hi,

Could someone help me out with a macro to find duplicate files in a given folder.

Regards,
Ren
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Windows will not allow 2 files with the same name in a given folder, so I do not understand what you mean with "duplicate files in a given folder".

Please explain in detail what you need.
 
Upvote 0
For instance i have file with the Name Apple.TXT, Apple.XLS,Apple.Doc

I need a macro that will let me know, that a File name with Apple is available in folder 3 times or x times

I hope that is clear
 
Upvote 0
Code:
Sub TraceDuplicateFiles()
    FolderName = "C:\Files\"  'ADJUST HERE
    FName = Dir(FolderName & "*.*")
    Do While Len(FName)
        sFiles = sFiles & "#" & FName
        FName = Dir()
    Loop
    sq = Split(Mid(sFiles, 2), "#")
    For i = LBound(sq) To UBound(sq)
        FName = Dir(FolderName & Left(sq(i), InStrRev(sq(i), ".") - 1) & ".*")
        Do While Len(FName)
            If FName <> sq(i) Then Range("A" & Rows.Count).End(xlUp).Offset(1) = FName
            FName = Dir()
        Loop
    Next
    Columns(1).Sort [A1]
End Sub
 
Upvote 0
Hi Wigi,

I tried the macro, however i did not get any result. Could you please re-check it again. It neither gave me the count of the duplicate files or the name of the duplicate file.

Regards,
Ren
 
Upvote 0
The result of the macro (all files that are duplicates) are output on the active sheet, in column A.

Make sure you have changed the path of the folder (now it is C:\Files\) Do not forget to add the \ at the end of the path.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top