关于我的问题,我发现最好的是:
var filePaths = Directory.EnumerateFiles(@"C:", "chrome.exe", new EnumerationOptions
{
IgnoreInaccessible = true,
RecurseSubdirectories = true
});
Console.WriteLine(filePaths);
但我不知道如何将appPath输出到字符串,它输出的是:
System.IO.Enumeration.FileSystemEnumerable`1[System.String]
它如何输出:C:\Program Files\Google\Chrome\Application
对于任何应用程序而不是Chrome。。。
filePaths是多个字符串的集合,因此您需要对其进行迭代。
foreach (string path in filePaths)
{
Console.WriteLine(path);
}
您也可以考虑像String.Join((.这样的函数