首页 > 解决方案 > 查找程序的路径(python)

问题描述

所以我正在尝试查找可执行文件的路径,现在我的代码正在检查每个目录,所以感觉不是最好的选择,可能需要一些时间进行一些搜索

def findFile(filename):
    newFileName=filename+'.exe'
    for root,dirs, files in os.walk("C:\\"):
        for f in files:
            if newFileName in os.path.join(root,f).lower() and "install" not in  os.path.join(root,f).lower():
                return os.path.join(root,f)
    return None

所以我正在寻找不包含单词 install 的 exe 文件,因为我现在只想启动程序任何建议以使其更有效

标签: pythonsearchdirectory

解决方案


推荐阅读