C#+.NET:在计算机中查找类似chrome.exe的应用程序的路径(所有磁盘、所有目录)



关于我的问题,我发现最好的是:

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((.这样的函数

相关内容