We help IT Professionals succeed at work.

VBA or Script to identify files which are duplicate in a folder

141 Views
Last Modified: 2017-03-14
i have a very tricky situation with my files.

i have a folder which has duplicates like this, how can i delete one copy of them and delete the other so that there is unique left?

is there any way to do this automatically without manual process?

Anonymizing-Data.xlsm
Anonymizing-Data-wngz.xlsm

Creating-A-Search-Box-40t1.xlsm
Creating A Search Box.xlsm

Contacts List Template.xlsm
Contacts-List-Template.xlsm
Comment
Watch Question

Rob HensonFinance Analyst
CERTIFIED EXPERT

Commented:
I don't have any suggestions as that is not my field but no doubt the question will be asked; how will you determine which file to keep and which to delete?

Thanks
Rob H
KimputerIT Manager
CERTIFIED EXPERT

Commented:
VBA could do the trick,

enumerate all files in two loops, compare MD5 hash of the two files. Delete if the same.
To reduce system load, only compare if first x letters of the file name (maybe 3 or 5?) are the same.
However, you will NOT have a choice for the file name (if the shorter file name is prettier, but it's the one in the first loop, you obviously can't delete it).
David Johnson, CDSimple Geek from the '70s
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
I would use a utility like beyond compare
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Flora EdwardsMedicine

Author

Commented:
thanks everyone.

MacroShadow Solution was absolutely perfect.  thanks very much. this is extraordinary
CERTIFIED EXPERT

Commented:
You're welcome, glad to help!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions