- Home /
How do you display a list of folders in a directory?
I'm trying to make a list of all the folders in a directory and then create a GUI and display it on there.
Is it something like this?
string[] dir = Directory.GetDirectories(Application.persistentDataPath);
I'm using C#
Answer by Graham-Dunnett · May 10, 2013 at 09:30 AM
Yes that's what you do.
I'm getting an error:
NullReferenceException: Object reference not set to an instance of an object
WorldLoad.OnGUI () (at Assets/Scenes/Game/Scripts/$$anonymous$$enu/WorldLoad.cs:31)
Here's the line:
foreach(string d in dir) {
"Yes that's what you do." as long as you don't do a standalone build, right?
Why wouldn't this work for a standalone build?
Because that particular folder doesn't exist once built. If you want to find assets once compiled you need to need to look into "loading resources at runtime". Have a look at the link below:
https://docs.unity3d.com/$$anonymous$$anual/LoadingResourcesatRuntime.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Populating dropdown with folders from selected directory 0 Answers
How do I load a config (.cfg) or ini file? 2 Answers
Add files to folder 1 Answer