如何在主操作系统路径(而不是pythonpath)上找到文件?
如何使用Python找到文件在系统路径上的文件位置(即Windows%路径%环境变量)?
这与python路径,内置sys.path
或环境变量pythonpath
,而是关于终端中存在的主要操作系统的路径,例如cmd,bash等。
首选项:
- 直接python代码(而不是运行shell命令)
- 基于python 3的解决方案,使用
pathlib.path.path
- platform-
notes- notes notes
- i'i' m不想只是获取路径(即
os.environ ['path']
),而是在路径上找到特定文件的解决方案,类似于Windowswhere < /code>命令或linux
哪个
命令,但使用python代码。 - 我希望找到任何文件,而不仅仅是可执行文件(理想情况下,您可以放入文件模式并获得所有结果),不同于 this Q&amp; A 。
How can I find a file the location of a file on the System PATH (i.e. in Windows %PATH% environment variable) with Python?
This is not about the Python Path, the built-in sys.path
, or the environment variable PYTHONPATH
, but the PATH from the main OS that is present in terminals such as CMD, bash, etc.
Preferences:
- Direct Python code (rather than running a shell command)
- A Python 3-based solution, using
pathlib.Path
- Platform-independent
Notes
- I'm not looking to just get the PATH (that is just
os.environ['PATH']
), but a solution to find a particular file on the PATH, similar to the Windowswhere
command, or linuxwhich
command, but using Python code. - I'm looking to find any file, not just executables (ideally you could put in a file pattern and get all results), different from this Q&A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论