【问题标题】:Locate Another Application's Data Directory定位另一个应用程序的数据目录
【发布时间】:2014-08-29 21:12:19
【问题描述】:

给定一个应用程序“Foo”,它可以在 Windows Vista 下安装或不安装清单(进入“程序文件”),该应用程序还具有应用程序安装路径“bar”的子目录:

如何从另一个不使用文件和注册表虚拟化的 (C#) 应用程序中找到 \foo\bar 的实际路径。

有没有一种干净的方法可以做到这一点?

【问题讨论】:

  • 不是真的;这个想法是你不应该弄乱其他应用程序数据。
  • 如果您知道持有“Foo”的程序集的名称,则可以使用 Assembly.Location 属性来查找路径。

标签: c# windows-vista


【解决方案1】:

在system.IO中,有一个方法叫Directory.GetDirectories

您可以使用它进行迭代,检查名称 foo(如果它在根目录中),然后进入 bar。

如果您还需要驱动器名称,您可以使用DriveInfo.GetDrives。这些应该可以帮助您搜索它。示例:

    DriveInfo[] allDrives = DriveInfo.GetDrives();

    foreach (DriveInfo d in allDrives)
    {
        string[] dirs = Directory.GetDirectories(d.name, "foo\bar");
        foreach (string dir in dirs) 
        {
          //you have your foo bar!
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 2012-05-29
    • 2011-08-22
    • 2011-08-12
    • 1970-01-01
    相关资源
    最近更新 更多