Get file list from a directory on Android

Hello !

I looked for a while here and I can’t find a solution to my problem :

I got some files in a subfolder in resources. At runtime, I want to dynamically create some list according to the files name.
On editor no problem here.

But I can’t find any solution on android because WWW can’t access to a directory, it works only when we have the full path (and i can’t do that here because it would be the opposite of what I’m trying to do).

Anyway, is this true ? I only see old post, is there a new unity solution to getFiles from directory on android ?

If not, I think that I can get the file’s list before building on Android.
But I don’t want to launch a first time on editor, list everything in a new file and then build on android with this file included, because the list can change at each build …
So, is that possible to write code on pre processor ? I mean, when i click on File > Build & run, is it possible to launch a script that stored my files name and after build on Android with that new file / list.

I don’t know if i make myself clear, tell me

Thanks for reading, hope someone already thought about that.

If the files are local this should work:

I solved the problem after I added my files in this directory inside the projec Assets/StreamingAssets/

then I read it inside the code

#if UNITY_ANDROID
      string  path = "jar:file://" + Application.dataPath + "!/assets/alphabet.txt";
        WWW wwwfile = new WWW(path);
        while (!wwwfile.isDone) { }
        var filepath = string.Format("{0}/{1}", Application.persistentDataPath, "alphabet.t");
        File.WriteAllBytes(filepath, wwwfile.bytes);

        StreamReader wr = new StreamReader(filepath);
            string line;
            while ((line = wr.ReadLine()) != null)
            {
            //your code
            }
#endif

Use Better Streaming Assets

It works on on Android Platform Also. Make sure you are you are passing the path correctly.

    string path= Application.persistentDataPath + "/MyFolder/";
DirectoryInfo dataDir = new DirectoryInfo (path);
	try {
		FileInfo[] fileinfo = dataDir.GetFiles ();
		for (int i=0; i<fileinfo.Length; i++) {
			string name=fileinfo *.Name;*
  •   		Debug.Log("name  "+name);*
    
  •   	}*
    
  •   } catch (System.Exception e) {*
    
  •   	Debug.Log (e);*
    
  •   }*