• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
12
Question by ClandestineMan · Jan 18, 2011 at 05:50 AM · editorshowinexplorer

How to Implement "Show in Explorer"

I am working on a project and some editor tools and I would like to have the ability to have the user click a button to Show the item in the Explorer window. Or have the tool auto open a folder after it is done processing what it needs to do. I have looked around and Google this, but it looks like every link is to some bug related to Show in Explorer. Not how to implement it.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Flynn · Jan 18, 2011 at 06:00 AM 1
Share

What is is "The Explorer"?

avatar image ClandestineMan · Jan 19, 2011 at 09:47 PM 0
Share

The Explorer Window is the folder window.

4 Replies

· Add your reply
  • Sort: 
avatar image
19
Best Answer

Answer by yoyo · Jan 18, 2011 at 07:22 AM

The command line you want is:

explorer.exe /select,<path to file or folder>

You can run a command line such as this with System.Diagnostics.Process.Start, as follows (C#) ...

public void ShowExplorer(string itemPath)
{
    itemPath = itemPath.Replace(@"/", @"\");   // explorer doesn't like front slashes
    System.Diagnostics.Process.Start("explorer.exe", "/select,"+itemPath);
}
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image · Jan 18, 2011 at 07:49 AM 0
Share

Very useful, upvoted ty.

avatar image yoyo · Feb 11, 2011 at 11:27 PM 0
Share

Note that this will only work under Windows, not on the $$anonymous$$ac.

avatar image hof · Aug 05, 2011 at 05:56 AM 0
Share

No chance to do this with a mac?

avatar image nahoy · Nov 25, 2013 at 11:32 PM 2
Share

For mac you can just do : EditorUtility.RevealInFinder(path)

avatar image
47

Answer by coeing · Nov 18, 2014 at 10:01 AM

I needed this functionality today as well. As it turned out there is a very easy solution:

 EditorUtility.RevealInFinder(path)

nahoy mentioned that it works for Mac, I can confirm that it works on Windows, too. No need to work with System.Diagnostics.Process.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image furic · Mar 13, 2015 at 12:34 AM 0
Share

Yup it works, too easy~! To be added, Application.dataPath return the path of Assets folder, so together it is: (e.g. Resources folder)

  EditorUtility.RevealInFinder(Application.dataPath + "/Rescources/")

avatar image guavaman · Jun 26, 2015 at 07:27 PM 3
Share

This is the best answer and should be marked as the answer for this question.

avatar image Lohoris2 · Oct 03, 2017 at 02:42 PM 0
Share

Unfortunately, this only works in the Editor. Which maybe it's what the OP asked, but many other people will need to do that at runtime…

avatar image arichards · Aug 06, 2019 at 08:33 PM 0
Share

This works great, but it reveals the last component of the path in finder/explorer. That is, if you pass in a specific directory, it takes you to that directory's parent and highlights the specified directory.

$$anonymous$$y solution is to pass in the first file in the directory if one exists:

 var path = Path.Combine(Application.dataPath, "Resources");
 var file = Directory.EnumerateFiles(path).FirstOrDefault();
 if (!string.IsNullOrEmpty(file))
     EditorUtility.RevealInFinder(Path.Combine(path, file));
 else
     EditorUtility.RevealInFinder(path);

Obviously the downfall here is if there is no file in the directory, in which case it falls back to the original behaviour...

avatar image
13

Answer by nathanthesnooper · Oct 21, 2016 at 09:33 PM

I DID IT! ! ! SO EASY HARD TO BELIEVE!

 Application.OpenURL("file://[dir]");

For some reason, this opens the actual file explorer instead of the browser one. FINALLY!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lohoris2 · Oct 03, 2017 at 02:46 PM 0
Share

Would be nice, but no, doesn't work.

avatar image stevesan · Aug 17, 2018 at 07:38 PM 0
Share

this works for me! windows 10, unity 2018.2.1f1

avatar image FunFoxRR · Apr 11 at 01:24 PM 0
Share

Change the file:// to file:///

avatar image
3

Answer by AnomalusUndrdog · May 09, 2013 at 04:45 AM

Here's how to do it for both Mac and Windows. There is currently no platform defines for the current OS that you are in, so my code tries both Windows Explorer and Mac Finder, and just skips any error. So OpenInFileBrowser is the cross-platform convenience function that will work in both OS's.

My code will also automatically select/highlight the file (if the argument passed is a file), or open the contents of a folder (if the argument passed is a folder).

I put this code in public domain, feel free to use it!

     public static void OpenInMacFileBrowser(string path)
     {
         bool openInsidesOfFolder = false;
 
         // try mac
         string macPath = path.Replace("\\", "/"); // mac finder doesn't like backward slashes
 
         if (Directory.Exists(macPath)) // if path requested is a folder, automatically open insides of that folder
         {
             openInsidesOfFolder = true;
         }
 
         //Debug.Log("macPath: " + macPath);
         //Debug.Log("openInsidesOfFolder: " + openInsidesOfFolder);
 
         if (!macPath.StartsWith("\""))
         {
             macPath = "\"" + macPath;
         }
         if (!macPath.EndsWith("\""))
         {
             macPath = macPath + "\"";
         }
         string arguments = (openInsidesOfFolder ? "" : "-R ") + macPath;
         //Debug.Log("arguments: " + arguments);
         try
         {
             System.Diagnostics.Process.Start("open", arguments);
         }
         catch(System.ComponentModel.Win32Exception e)
         {
             // tried to open mac finder in windows
             // just silently skip error
             // we currently have no platform define for the current OS we are in, so we resort to this
             e.HelpLink = ""; // do anything with this variable to silence warning about not using it
         }
     }
 
     public static void OpenInWinFileBrowser(string path)
     {
         bool openInsidesOfFolder = false;
 
         // try windows
         string winPath = path.Replace("/", "\\"); // windows explorer doesn't like forward slashes
 
         if (Directory.Exists(winPath)) // if path requested is a folder, automatically open insides of that folder
         {
             openInsidesOfFolder = true;
         }
         try
         {
             System.Diagnostics.Process.Start("explorer.exe", (openInsidesOfFolder ? "/root," : "/select,") + winPath);
         }
         catch(System.ComponentModel.Win32Exception e)
         {
             // tried to open win explorer in mac
             // just silently skip error
             // we currently have no platform define for the current OS we are in, so we resort to this
             e.HelpLink = ""; // do anything with this variable to silence warning about not using it
         }
     }
 
     public static void OpenInFileBrowser(string path)
     {
         OpenInWinFileBrowser(path);
         OpenInMacFileBrowser(path);
     }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image voldemarz · May 06, 2014 at 12:15 PM 0
Share

Can use Application.platform to check if it is Win or $$anonymous$$ac

avatar image Nition · Dec 03, 2015 at 04:08 AM 2
Share

Shorter version that should also work on Windows and $$anonymous$$ac:

  string path = path.TrimEnd(new[]{'\\', '/'}); // $$anonymous$$ac doesn't like trailing slash
  Process.Start(path);

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The Script Equivilent of dragging a hierarchy of meshes over a preexisting prefab? 0 Answers

Tracking down causes of Editor errors. 1 Answer

Unity Editor crashing when editing scripts referenced from GameObjects 1 Answer

Save scene event when the user save the scene in the editor 1 Answer

Editor utility for handling nested prefabs.. 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges