c#判断某个命令是否在PATH环境变量中
文章目录
public static bool IsInPATH(string command)
{
bool isInPath = false;
// 判断PATH中是否存在 命令
foreach (string test in (Environment.GetEnvironmentVariable("PATH") ?? "").Split(';'))
{
string path = test.Trim();
if (!String.IsNullOrEmpty(path) && File.Exists(Path.Combine(path, command)))
{
isInPath = true;
break; // 如果在PATH中找到 ,则退出循环
}
}
return isInPath;
}IsInPATH("ffmpeg.exe"); // 返回 bool值

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论