I'm trying to create a 'Show' button in my application. I want this to either open Windows Explorer into the selected folder, or open into the folder and highlight the selected file.
I know Process.Start("explorer.exe", fileName) does this, however it opens in a version of Explorer that can't be navigated. Pressing 'Up Directory' for example opens a new window.
The code I've got below does everything I want it to, except that when the path is a file, it opens a new window instance each time the button is clicked. Whereas when the path is a folder, it opens an already existing window if one exists at that path.
I'm hoping I can have the same functionality for file selection. But I can't figure out how to do it.
Any and all help is appreciated!
static void OpenInWin(string path) {
path = path.Replace("/", "\\");
ProcessStartInfo pi = new ProcessStartInfo("explorer.exe") {
WindowStyle = ProcessWindowStyle.Normal,
UseShellExecute = true
};
if (Directory.Exists(path)) { // We are opening a directory
pi.FileName = path;
pi.Verb = "open";
} else {
pi.Arguments = "/select, \"" + new FileInfo(path).FullName + "\"";
}
try {
Process.Start(pi);
} catch(Exception e) {
UnityEngine.Debug.Log(e);
}
}