Does DirectoryInfo GetFiles work on Android ?
I need to list up all png files in a sub folder of the assets folder in my exported android project.
I have verified that the sub folder is in the assets folder of my exported android project. It has some .png files in it.
However, I keep getting the error: DirectoryNotFoundException .
Does DirectoryInfo GetFiles work on android ?
Sample Code:
string streamingAssetsPathAndroid = "jar:file://" + Application.dataPath + "!/assets/";
string subFolderPath = "Some/Other/" + "folder";
string fullpath = streamingAssetsPathAndroid + subFolderPath;
DirectoryInfo dirInfo = new DirectoryInfo(fullpath);
FileInfo[] fileInfo = dir.GetFiles("*.png");
Result:
DirectoryNotFoundException: Directory 'jar:file:/data/app/com.your.company.game.apk!/assets/Some/Other/folder' not found.
I have tried various other paths like:
string streamingAssetsPathAndroid = "jar:file://" + Application.dataPath + "!/assets/";
Or
string streamingAssetsPathAndroid = "file://" + Application.dataPath + "!/assets/";
Or
string streamingAssetsPathAndroid = "Application.dataPath + "!/assets/";
Or
string streamingAssetsPathAndroid = "assets/";
and then combining it with the sub folder path. But I get a DirectoryNotFoundException error every time.
Please let me know if there is a proper/recommended way to do this.
ref : http://answers.unity3d.com/questions/569445/does-directoryinfo-getfiles-work-on-android-.html
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
Unity 2017 New Features - Sprite atlas, (C#) (0) | 2017.10.18 |
---|---|
How to get multiple files with different extension? C# unity (0) | 2017.10.12 |
Reading file from StreamingAssets, Android(StreamingAssets ) (0) | 2017.10.10 |
이미지 로딩 WWW 과 ReadAllBytes 의 성능차이 (0) | 2017.10.09 |
Texture2D를 Sprite로 변경 <SpriteRenderer> (0) | 2017.10.09 |
The sub folders and pngs are in my streaming assets folder in unity. When it gets exported as a google android project, they are in the android project's assets folder.
Is there some (alternative) way to list up all .png files in my sub folder ?
Hmm, is there a reason you don't use Application.streamingAssetsPath like suggested on this page?
Also keep in mind, like mentioned on the doc page, on android the files are not in a folder, they are within a jar file. So GetFiles won't work on this path since it's not an actual path. If you want to "browse" your folder you need a zip-library to open the jar manually.
GetFiles works perfectly well on real folders as long as you have file permission.
I actually have tried using: string streamingAssetsPathAndroid = Application.streamingAssetsPath;
Which pretty much results in the same path string and the same folder not found error for me.
I may have to consider that it may not be possible to use Directory.GetFiles on a unity game exported to google android project...
Bunny's right you can't scan the directory because it is in a ZIP file. You can use a ZIP library to examine the JAR and get files from it.
I use this: http://www.icsharpcode.net/opensource/sharpziplib/ for a lot of stuff.