Created
January 11, 2019 10:33
-
-
Save drZool/498784884c5fedcd71835c3c98811edf to your computer and use it in GitHub Desktop.
Helper functions for Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class WindowsHelper | |
| { | |
| /// <summary> | |
| /// Selects the file in explorer. If it does not exist select the first parent directory that exists | |
| /// </summary> | |
| /// <param name="possibleFile">Possible file.</param> | |
| [System.Diagnostics.Conditional ("UNITY_EDITOR_WIN")] | |
| [System.Diagnostics.Conditional ("UNITY_STANDALONE_WIN")] | |
| public static void SelectFileInExplorer (string possibleFile) | |
| { | |
| string arguments = ""; | |
| var fileInfo = new System.IO.FileInfo (possibleFile); | |
| if (fileInfo.Exists) { | |
| arguments = "/select,\"" + possibleFile.Replace ("/", "\\") + "\""; | |
| } else { | |
| var dir = fileInfo.Directory; | |
| while (!dir.Exists && dir != null) { | |
| dir = dir.Parent; | |
| } | |
| if (dir == null) | |
| return; | |
| arguments = "/root,\"" + dir.FullName.Replace ("/", "\\") + "\\\""; | |
| } | |
| //Debug.Log ("start: explorer.exe " + arguments); | |
| System.Diagnostics.Process.Start ("explorer.exe", arguments); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment