RT,就是想找出命名冲突的可执行文件。日积月累的,PATH 环境变量里乱七八糟堆了一堆东西,很可能想叫一个命令出来,结果实际执行的是另一个地方的程序。
Python 脚本
import os
path = os.environ['PATH']
folders = path.split(';')
files = {}
SUFFIX = ('.exe', '.bat', '.ps1', '.com', '.cmd', '.vbs', '.vbe', '.js', '.jse', '.wsf', '.wsh', '.msc')
for folder in folders:
    if os.path.exists(folder):
        for file in os.listdir(folder):
            full_path = os.path.join(folder, file)
            if os.path.isfile(full_path):
                if file in files:
                    files[file].append(full_path)
                else:
                    files[file] = [full_path]
                    
str_suffix = lambda s: s[s.rfind('.'):]
for file, paths in files.items():
    if len(paths) > 1 and (str_suffix(file).lower() in SUFFIX):
        print(f"[[[ {file} ]]] is found in:")
        for path in paths:
            print(f"  {path}")
            
os.system('pause')
 
执行这个脚本应该没什么特别的Python 版本要求,大概只要是Python 3 就行。这个脚本遍历PATH 里的所有文件夹,找出其中所有重名的文件,然后打印出来。SUFFIX 是可执行文件的后缀名,只有后缀在这里面的文件会显示出来。把脚本保存成一个.py 文件然后执行,效果应该类似下面这样:




















