# Search for executable files which appears in PATH more than once.
# Executable extensions for both cmd.exe and 4dos.com are counted.

import os

ext_winnt = [x.lower() for x in os.environ["PATHEXT"].split(";")]
ext_4dos  = [x.lower() for x in os.environ.keys() if x[0] == "."]
executables = (ext_winnt or [".bat", ".btm", ".com", ".exe"]) + ext_4dos

table = {}

for dir in os.environ["PATH"].split(os.pathsep):
    for file in os.listdir(dir):
        name, ext = os.path.splitext(file.lower())
        if ext == "": ext = "."
        if ext in executables:
            if not table.has_key(name): table[name] = []
            table[name].append(os.path.join(dir, file))

for name, bunch in table.items():
    if len(bunch) > 1:
        count = len([file for file in bunch if os.path.isfile(file)])
        if count > 1:
            print count, name
