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#.

1 Like

8 Answers

8

http://www.starscenesoftware.com/unifilebrowser.html

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... :(

There is one on the wiki: http://wiki.unity3d.com/index.php?title=ImprovedFileBrowser

Thanks, does it works with web versions?

well, I would think it should not for security reason. Not sure though.

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 Mac 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

You originally didn't mention about requirement to run this in web player. I (as all answerers before me) assumed standalone. No operations related to local file system works in web player. There is no work around this, unless you develop in Flash, which, as far as I know, have a possibility of accessing files on local machine.

you can write a function like this:

void OpenFolder (string fileName )
{
       System.Diagnostics.Process.Start(fileName);
}

the string fileName can be the path to a folder to open the explorer, it will open the file if you include the file name in the string

can't tell you if this works on MAC however

Thank you for your answer, but I asked this question 8 years ago!

Originally asked 12 years ago, got answered after 8 and yet it just helped me out!

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: Unity Asset Store - The Best Assets for Game Making

I’ve been searching for a way to do that for more than a year… and finally found how to do it :slight_smile:

can anyone tell me how can I give access in android mobile gallery through explorer for pick His/Her picture and use it in app…
I just want from anyone to tell correct path…so that I can easily access to my android mobile during running my
app…

I suggest that you buy this asset, it has many features for Android and its support is so good https://www.assetstore.unity3d.com/en/#!/content/10825

I spent a long time looking for a good solution to this. I really wanted to make use of the system file browser and eventually found this free asset:

Hello, you can use this :

Application.OpenURL(“file:///” + your Path);

Thanks,it works,i dont know why,but "Process " works on editor but not on runtime. i got "(Exception) Win32Exception: SuccessSystem.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo)".