我怎么觉得可能不完全限定使用环境的路径下的文件?不完全、路径、环境、我怎么

2023-09-04 22:40:48 作者:带着兔子去拔yá@

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

 
精彩推荐
图片推荐