Skip to content

Instantly share code, notes, and snippets.

@drZool
Created January 11, 2019 10:33
Show Gist options
  • Select an option

  • Save drZool/498784884c5fedcd71835c3c98811edf to your computer and use it in GitHub Desktop.

Select an option

Save drZool/498784884c5fedcd71835c3c98811edf to your computer and use it in GitHub Desktop.
Helper functions for Windows
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