Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Kyoumi · Jan 19, 2017 at 10:44 AM · androidwwwdirectorypreprocessor

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by nasir_41 · Jan 19, 2017 at 04:33 PM

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 [i].Name;
             Debug.Log("name  "+name);
         }
     } catch (System.Exception e) {
         Debug.Log (e);
     }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kyoumi · Jan 20, 2017 at 08:14 AM 0
Share

Oh really ? Where should I put my folder ? For now it's in the Resources folder, and i can't find it on android.

Should i use strea$$anonymous$$gassets folder ?

avatar image WolffCheng · Jul 12, 2018 at 03:12 PM 0
Share

It didn’t work.... directory. Get file doesn’t work on android...

avatar image
1

Answer by shadyshrif · Jul 04, 2017 at 07:39 PM

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
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ginxx009 · Feb 28, 2018 at 06:52 AM 0
Share

hi i know it's a bit late but is this still working you know. Cause i'm having a lil bit of a problem on reading json file on android.

avatar image
1

Answer by rich-gg · Nov 07, 2019 at 11:21 AM

Use Better Streaming Assets https://assetstore.unity.com/packages/tools/input-management/better-streaming-assets-103788

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by doublemax · Jan 19, 2017 at 10:44 AM

If the files are local this should work:

https://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kyoumi · Jan 19, 2017 at 10:50 AM 0
Share

On Editor yes; it works like this :

         DirectoryInfo levelDirectoryPath = new DirectoryInfo(dbPath);
         FileInfo[] fileInfo = levelDirectoryPath.GetFiles("*.*", SearchOption.AllDirectories);
 
         foreach (FileInfo file in fileInfo)
         {
             // etc etc 
         }
 

But it doesn't work on Android

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sharing violation when deleting a directory used by a WWW object 0 Answers

Streaming Assets android 0 Answers

Loading Pictures from Android Device into game at runtime 1 Answer

Android Persistent Data loading fails 1 Answer

About www.error! 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges