【问题标题】:C# + .NET : Find the path of an app like chrome.exe in the computer (all disks, all directories)C# + .NET : 在计算机中查找 chrome.exe 等应用程序的路径(所有磁盘、所有目录)
【发布时间】:2022-01-19 08:38:26
【问题描述】:

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

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...

【问题讨论】:

    标签: c# .net windows directory subdirectory


    【解决方案1】:

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

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

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

    【讨论】:

    • 你最好!我会试试这个来找到我的启动器的每条路径......
    • 嗯再次嗨...我如何使用它:`Process chrome = new Process(); chrome.StartInfo.FileName = $"我们找到的路径";铬。开始(); `
    • 只需 chrome.StartInfo.FileName = chromePath,其中 chromePath 是一个字符串
    • 顺便说一句,你真是个天才。是的,你的权利,但 chrome 路径是用 foreach 建立的 ...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多