C# 打开文件所在位置

| 发布     | 分类 C#  | 标签 C#  Mac 



  // 打开文件

  // 定位到文件
	System.Diagnostics.Process.Start("Explorer.exe","/select, \"c:\\windows\text.txt\"");

看Windows可以用Explorer来实现,我想Mac的Finder应该有对应的方式。于是找呀找 没发现有Finder的执行文件。后来就想open命令,找到了open命令所在位置"/usr/bin/open"。之前一直用open xxx,目录还好,文件可是会直接打开文件的。于是网上找open命令的参数,找了半天没找到。是我傻X了,用 open --help不就行。于是就找到了 open -R xxxx

open --help

open: unrecognized option `--help'
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-b <bundle identifier>] [-a <application>] [filenames] [--args arguments]
Help: Open opens files from a shell.
      By default, opens each file using the default application for that file.  
      If the file is in the form of a URL, the file will be opened as a URL.
      -a                Opens with the specified application.
      -b                Opens with the specified application bundle identifier.
      -e                Opens with TextEdit.
      -t                Opens with default text editor.
      -f                Reads input from standard input and opens with TextEdit.
      -F  --fresh       Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
      -R, --reveal      Selects in the Finder instead of opening.
      -W, --wait-apps   Blocks until the used applications are closed (even if they were already running).
          --args        All remaining arguments are passed in argv to the application's main() function instead of opened.
      -n, --new         Open a new instance of the application even if one is already running.
      -j, --hide        Launches the app hidden.
      -g, --background  Does not bring the application to the foreground.
      -h, --header      Searches header file locations for headers matching the given filenames, and opens them.

 open -R /Users/macserver/Downloads/unity_guidref_3.png
System.Diagnostics.Process.Start( "/usr/bin/open", "-R /Users/macserver/Downloads/unity_guidref_3.png");

        public void RevealInFinder(string path)
            #if UNITY_STANDALONE_OSX
            System.Diagnostics.Process.Start( "/usr/bin/open", "-R " + path);

            #elif UNITY_STANDALONE_WIN
            path = path.Replace("/", "\\");
            System.Diagnostics.Process.Start("Explorer.exe", "/select, \"" +path+ "\"");
上一篇: Unity C# 多线程下载
下一篇: Unity 视频相册