- Home /
Getting list of files from specified folder
Hi everybody!
How can i get ALL the files from custom path(non-unity assets folder) into array, or some kind of list?
P.S. Sorry for my bad English.
Answer by _MGB_ · Jan 20, 2011 at 11:43 AM
In C# you can do it with:
using System.IO;
DirectoryInfo dir = new DirectoryInfo(myPath);
FileInfo[] info = dir.GetFiles("*.*");
foreach (FileInfo f in info)
{
...
}
Thank you, didnt see it, because i was already writing an JS-oriented answer.
I'm sure that your answer will be useful for C# users in Unity.
Answer by DrProgrammer · Jan 20, 2011 at 11:44 AM
I got my answer suddenly.
Here it goes:
In the top of the js script
import System.IO;
And in the function
var filePaths : String[] = Directory.GetFiles("C:/Users/Altair-X/Music/","*.mp3");
Where "filePaths : String[]" - is an array of string, which contains paths to the files.
"C:/Users/Altair-X/Music/" - where to look for.
"*.mp3" - what to look for.
import? I didn't know you could do that with Unity JS! It... it's like a whole new world of possibilities has been opened up to me! I've been looking all over for that! Thank You!
I'd vote thumbs up, but I have no reputation. I'm sketchy.
$$anonymous$$an, i'm from the future. Year 2016. I wanted to tell you that... I LOVE YOU DUD$$anonymous$$
You call this "future"? Pff, amateur. ;)
this work perfect just i need to change capital latter S to small s in string and work. thanks.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Get list of all files in a directory? 3 Answers
Android file path? 0 Answers
Build data path and projects data path on postprocess build. 0 Answers
Writing Editor Script, Getting Weird Null Reference Exception 2 Answers