1

There are plenty of apps that find duplicate files, however I haven't found any that work based on filename only comparison.

There appears to be an app for Windows that does this:

Anti-Twin

But out of all of the various apps for macOS, there doesn't appear to be one. I'd even be happy for a shell app (*nix) that works on macOS.

  • Are you looking to find duplicates between 2 trees or all the duplicates in a single one? – Steve Barnes Apr 14 '18 at 11:56
  • Both or recursively under the same tree branch. Perhaps most frequently I'll be looking in a singular tree and only in the same 1st level, but I will want to do the others as well @SteveBarnes. – ylluminate Apr 14 '18 at 20:03
1

Since you are on macOS you already have python installed so a simple python script can do the job:

#!/usr/bin/env python
from __future__ import print_function
import os
import sys
from collections import defaultdict
def get_fnames(fnamedict, treeroot="."):
    """ Traverse a directory tree putting locations into a dictionary """
    for root, dirs, files in os.walk(treeroot):
        for fname in files:
            fnamedict[fname].append(root)

def print_dups(fnamedict):
    """ Given a dictionary of filenames & paths output any names with more than one path """
    dupsfound = False
    for fname, paths in fnamedict.items():
        if len(paths) > 1:
            print("{} occurs {} times:".format(fname, len(paths)))
            print("\t{}".format('\n\t'.join(paths)))
            dupsfound = True
    if not dupsfound:
        print("No Duplicate Names Found")

def find_dupes(startdirs):
    """ Find the duplicates in a list of starting directories """
    fnamedict = defaultdict(list)  # Dictionary of filenames to paths
    for root in startdirs:
        print("Processing Tree Under:", root)
        get_fnames(fnamedict, root)
    print("Checking names for duplicates")
    print_dups(fnamedict)

if __name__ == "__main__":  # Only run if started directly rather than imported
    if len(sys.argv) == 1:  # No start points provided
        sys.argv.append(".")
        print("Scanning for duplicate names under current directory")
    find_dupes(sys.argv[1:])

If you save the above into a file called something like find_dup_names.py and set the executable flags with chmod you will be able to call it with a list of directory names or without in which case it will recurse the current directory. If you place the file somewhere that is on your path you will not need to supply the path to it every time you use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.