【问题标题】:Implement "Open Containing Folder" and highlight file实施“打开包含文件夹”并突出显示文件
【发布时间】:2011-02-19 05:54:23
【问题描述】:

在处理文件/文件夹的程序中,这可能是一个方便的功能。使用以下命令实际打开包含文件夹很容易:

System.Diagnostics.Process.Start( *path to folder* );

...但是我该如何去实际选择该父文件夹中的目标文件?如果我使用 Process.Start 方法,它实际上会尝试打开文件。

【问题讨论】:

标签: c# .net file windows-explorer


【解决方案1】:

根据Windows Explorer Command-Line Options,您只需使用/select 参数启动explorer 进程。

例如,“explorer /select,c:\Windows”将打开一个窗口,其中选择了c:\windows 文件夹。

所以只需Process.Start("explorer.exe", "/select," + filename) 就足够了。

【讨论】:

  • 谢谢!令我惊讶的是,在安装 Directory Opus 时,尽管明确引用了 explorer.exe,但还是使用了它。这是一件好事。
  • @Crosbie 那是因为 Directory Opus 挂钩到资源管理器并拦截对它的调用。
【解决方案2】:

使用/select, "filename" 命令行参数执行 Explorer.exe

System.Diagnostics.Process.Start(
    "explorer.exe", 
    string.Format("/select, \"{0}\"", filename));

【讨论】:

  • 这行不通,因为select的参数应该用逗号分隔,而不是用空格分隔
  • 只是为了说明,引用 (\"{0}\") 不是必需的,因为 explorer 会将 /select, 之后的任何内容视为路径(忽略开始和结束空格) - 所以 '/select,{0} '就够了...
【解决方案3】:

包含文件夹,Self 目录有多种表示方式!!! 简单的两种方法是..\. 不知道有什么区别!.. :D 来自 DOS 和 bat 文件...Start .Start .\. (Y)

尝试...这 2 项工作,但请检查这是否是您期望的解决方案!

System.Diagnostics.Process.Start("explorer.exe", @".\.");

或者

System.Diagnostics.Process.Start("explorer.exe", @".");

-

  • 有时应用程序从临时目录或其他目录运行(例如:在沙盒中...或在被防病毒软件扫描时...等:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-11
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    相关资源
    最近更新 更多