简体   繁体   中英

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

the best that i have found about my problem is:

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

But i dont know how to output to a string the appPath, it output this:

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

How can it output this: C:\Program Files\Google\Chrome\Application
And for any application instead of chrome...

filePaths is a collection of multiple strings, so you'll need to iterate through it.

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

You can also consider functions like String.Join() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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