繁体   English   中英

C# + .NET:在电脑中找到chrome.exe之类app的路径(所有磁盘,所有目录)

[英]C# + .NET : Find the path of an app like chrome.exe in the computer (all disks, all directories)

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

var filePaths = Directory.EnumerateFiles(@"C:\", "chrome.exe", new EnumerationOptions
{
    IgnoreInaccessible = true,
    RecurseSubdirectories = true
});
Console.WriteLine(filePaths);

但我不知道如何将 output 转换为 appPath 字符串,它是 output 这个:

System.IO.Enumeration.FileSystemEnumerable`1[System.String]

怎么会 output 这个:C:\Program Files\Google\Chrome\Application
对于任何应用程序而不是 chrome...

filePaths 是多个字符串的集合,因此您需要遍历它。

foreach (string path in filePaths)
{
  Console.WriteLine(path);
} 

你也可以考虑像String.Join()这样的函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM