[TIMOB-20223] Android: cannot list files on lib directory with Filesystem.getFiles - getDirectoryListing
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2018-06-12T21:35:40.000+0000 |
Affected Version/s | Release 5.1.1 |
Fix Version/s | n/a |
Components | Android |
Labels | android, filesystem, lib |
Reporter | Mauro Piccotti |
Assignee | Unknown |
Created | 2015-12-16T18:05:03.000+0000 |
Updated | 2018-06-12T21:35:45.000+0000 |
Description
Under lib directory I created a "repositories" dir, and under this dir I put some kind of commonjs modules I would like to load dinamically.
On iOS I do this and it works:
requirePath = "repositories/";
repositoriesDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + requirePath);
repositoriesFiles = repositoriesDir.getDirectoryListing();
// requires and other operations with those files
On Android apparently I cannot read files contained inside that directory.
I've found one guy with the same problem on your old forum, but now it's closed and there isn't an answer:
https://developer.appcelerator.com/question/179048/where-are-my-alloy-lib-files-in-the-filesystem-on-android
Hello [~pic], I have trieded a sample code on Android 4.4.2. It's working. I modified your code a bit. Use "requirePath = "/repositories/"" as like this.
My Test
[More info](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem.File-method-getDirectoryListing) on getDirectoryListing(). Hope this helps, Thanks.
Thank you for your answer Sharif but you did another thing, that slash doesn't solve my problem. I'm quite sure that getFile is bugged, and that question on Appcelerator's forum is exactly like mine. I was trying to work with conventions for avoiding mistakes and some configurations but apparently it work's only on iOS. My code: requirePath = "/repositories/"; repositoriesDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + "/repositories/"); Ti.API.info(repositoriesDir.resolve()); // the same with nativePath repositoriesFiles = repositoriesDir.getDirectoryListing(); Ti.API.info(repositoriesFiles); What it print: [INFO] : file:///android_asset/Resources//repositories/ [INFO] :
Hello, According to my code I can take a file from "resmon" folder through "getFile" and use it to another purpose. I tested this with Android 4.4.2. Seeing your code the "repositoriesDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + "/repositories/");" should be "repositoriesDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + requirePath );". Thanks.
I'm a bit confused because I'm speaking about listing files inside a folder, and not taking a file. It would be great if somebody would answer my question instead of doing other things, I also linked a discussion about one guy with exactly the same problem... I thank in advance anybody who will show me hot to list files inside "lib" directory with Android (in iOS it works). I need it for making a dynamic require of modules and for storing them inside an object literal.
I reproduced the bug in a test environment you can download from here: https://github.com/nonno/Ti.TestProject/tree/dynamic-require-bug (you should click on the label) It works on iOS, it doesn't work on Android 5. I would be happy if you reopen this bug.
With a default alloy project, I ran:-
And it works. I get back a list of files, which in this case is just one file
TiAPI : appicon.png
. back. You need to know the correct path the files are in to get them. Or in this case, you need to put the "repositories/" folder in `Resources/' folder. I.e. "Resources/repositories"Ran on both Alloy and Classic app. No issues.
I tested it with the new sdk 5.2.0.GA on a Samsung Galaxy Tab S2 with Android 5.0, it still doesn't work.
Ticket [TIMOB-25231] will resolve this issue. This fix is scheduled to be in Titanium 7.3.0.