标签:bin exist sha file sts public stat rem return
1 public static bool IsInPath(string command) 2 { 3 bool isInPath = false; 4 // 判断PATH中是否存在 命令 5 foreach (string test in (Environment.GetEnvironmentVariable("PATH") ?? "").Split(‘;‘)) 6 { 7 string path = test.Trim(); 8 if (!String.IsNullOrEmpty(path) && File.Exists(path = Path.Combine(path, command))) 9 { 10 isInPath = true; 11 break; // 如果在PATH中找到 ,则退出循环 12 } 13 } 14 15 return isInPath; 16 }
IsInPath("cmd.exe") // 返回 bool值
参考:http://csharptest.net/526/how-to-search-the-environments-path-for-an-exe-or-dll/index.html
标签:bin exist sha file sts public stat rem return
原文地址:https://www.cnblogs.com/jonah/p/14961357.html