【问题标题】:How to get the directory location of an application file using only the name of the application?如何仅使用应用程序名称获取应用程序文件的目录位置?
【发布时间】:2021-08-07 07:12:50
【问题描述】:

我正在用 python 编写代码,用户可以在其中输入安装在他们 PC 中的应用程序的名称,我的程序应该显示该应用程序的目录位置。

我已经使用“winapps.search_installed”来做同样的事情。它显示了一些应用程序的位置,但没有显示许多应用程序的位置。我的代码是这样的

for item in winapps.search_installed('Epic Games Launcher'):
    location=item.install_location
    print(location)

这里以我使用 Epic 游戏启动器为例。

除此之外还有什么有效的方法吗?

【问题讨论】:

  • 这是想重塑where <application>吗?
  • 是的,我正在尝试制作类似的东西
  • 在这种情况下,您必须首先清楚了解您真正想要完成的什么。 Windows 有多种安装程序的方法,这些程序的位置存储在多个目录中。除非您准确定义您的需求,否则我们无能为力。

标签: python python-3.x windows


【解决方案1】:

在 Windows 上,您可以在命令行中使用 where。例如:

 where notepad

您可以使用os.system('where notepad') 从您的 python 代码中运行它。

【讨论】:

  • 但是使用这个“where”,我只能得到内置系统应用程序的位置。我还需要获取外部安装应用程序的位置。
  • 呃,不,它会搜索你的PATH。但是,如果应用程序不在您的 PATH 中,则可以说这是错误的方法。
猜你喜欢
  • 2015-12-19
  • 2015-07-12
  • 1970-01-01
  • 1970-01-01
  • 2015-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多