我怎么觉得可能不完全限定使用环境的路径下的文件? [英] How do I find a file that may not be fully-qualified by using the environment path?

查看:168
本文介绍了我怎么觉得可能不完全限定使用环境的路径下的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可执行文件的名称,如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?

推荐答案

这似乎是这样做已经是一个pretty的好办法 - 因为据我所知,通过在 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天全站免登陆