- Home /
Opening a file explorer in run time?
Hello,
This is an advanced question, please read it carefully before answering.
For some reasons I need to give the player the ability to open a "file explorer". The player will click on a button while playing then a window will appear showing him/her the drives on his/her hard disk and then can open folders and browse files.
If this even possible in unity I need it also to access different operating systems (MAC or windows).
I'm not asking anyone to write me a full code or do my job, I just need someone to point me to the right direction... if it's even possible in unity.
I develop in C#.
Answer by ArkaneX · Nov 27, 2013 at 08:39 PM
If Eric5h5 or fafase answers are not what you seek for, and instead you want to run external program, you can use Process class. To open file explorer in Windows, you can use:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo("explorer.exe");
p.Start();
I think the Process class is not accessible in Unity. Not sure but I think I tried it and it would not load.
It works, at least in Windows. Not sure about $$anonymous$$ac though.
That's a good work around, why do I make a file explorer when I can use the regular file explorer? But how can I connect the opened file explorer to my game? for example: the player chooses a txt file to be used in the game.
That's weird... I get an error in Unity at
p.StartInfo = new System.Diagnostics.ProcessStartInfo("explorer.exe");
"The type System.Diagnostics.ProcessStartInfo' does not contain a constructor that takes
1' arguments"
But I can see in visual studio that it has a constructor that takes a string as an argument. The error is appearing in Unity only, not in visual studio
If you need web development you would have to add a Javascript method (the web Js not Unity Js) to your html file. Then you call it using http://docs.unity3d.com/Documentation/ScriptReference/Application.ExternalCall.html
Concerning file explorer with Js, should have that.
Answer by Eric5h5 · Nov 27, 2013 at 08:31 PM
Wow... that's really a handy asset you've got there, nice job Eric5h5. I really appreciate it but in the description you wrote:
"Note that UniFileBrowser does not work with web players, since Unity prevents web players from having local file access"
What the customer wants is a web version... :(
Answer by fafase · Nov 27, 2013 at 08:34 PM
There is one on the wiki: http://wiki.unity3d.com/index.php?title=ImprovedFileBrowser
well, I would think it should not for security reason. Not sure though.
Answer by PygmyMonkey · Aug 05, 2016 at 10:51 AM
Hello,
I made an Asset to use the Native File Browser from Windows and Mac in Unity at runtime, it's available on the Asset Store: https://www.assetstore.unity3d.com/en/#!/content/68064
I've been searching for a way to do that for more than a year... and finally found how to do it :)
Answer by pimichel · May 13, 2020 at 08:31 PM
Hello, you can use this :
Application.OpenURL("file:///" + your Path);