如何通过使用环境路径找到可能不完整资料的文件? [英] How do I find a file that may not be fully-qualified by using the environment path?

查看:121
本文介绍了如何通过使用环境路径找到可能不完整资料的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可执行文件名称,如cmd.exe,需要解决它的完全限定的路径。我知道exe出现在PATH环境变量中列出的目录之一中。有没有办法解决完整的路径,而无需解析和测试PATH变量中的每个目录?基本上我不想这样做:

I have an executable name, like "cmd.exe" and need to resolve it's fully-qualified path. I know the exe appears in one of the directories listed in the PATH environment variable. Is there a way to resolve the full path without parsing and testing each directory in the PATH variable? basically I don't want to do this:

foreach (string entry in Environment.GetEnvironmentVariable("PATH").Split(';'))
    ...

必须有一个更好的方法,对?

There has to be a better way, right?

推荐答案

这似乎是一个很好的方法,据我所知,通过目录搜索 PATH 环境变量是Windows尝试解决路径时所做的。

This seems like a pretty good way of doing it already -- as far as I know, searching through the directories in the PATH environment variable is what Windows does anyway when it's trying to resolve a path.

这篇关于如何通过使用环境路径找到可能不完整资料的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆