Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20223] Android: cannot list files on lib directory with Filesystem.getFiles - getDirectoryListing

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2018-06-12T21:35:40.000+0000
Affected Version/sRelease 5.1.1
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, filesystem, lib
ReporterMauro Piccotti
AssigneeUnknown
Created2015-12-16T18:05:03.000+0000
Updated2018-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

Comments

  1. Sharif AbuDarda 2015-12-17

    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

       $.nav.open();
       var requirePath = "/resmon/11788.png";
       var repositoriesDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + requirePath);
       //repositoriesFiles = repositoriesDir.getDirectoryListing();
       $.images.image = repositoriesDir;
       
       <Alloy>
       		<Window id="nav" backgroundColor="#fff">
       			<ImageView id="images" height='400' width='400' />
       		</Window>
       </Alloy>
       
    [More info](http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem.File-method-getDirectoryListing) on getDirectoryListing(). Hope this helps, Thanks.
  2. Mauro Piccotti 2015-12-17

    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] :
  3. Sharif AbuDarda 2015-12-22

    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.
  4. Mauro Piccotti 2015-12-22

    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.
  5. Mauro Piccotti 2016-01-05

    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.
  6. Ashraf Abu 2016-01-13

    With a default alloy project, I ran:-
       function doClick(e) {
       var repositoriesDir, repositoriesFiles ;
        
       Ti.API.info("Listing repository files");
        
       
       repositoriesDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory );
       Ti.API.info("Listing repository files at "+Ti.Filesystem.resourcesDirectory);
       Ti.API.info("Dir"+repositoriesDir);
       repositoriesFiles = repositoriesDir.getDirectoryListing();
        
       Ti.API.info(repositoriesFiles);
       }
       
       
       $.index.open();
       
    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"
  7. Ashraf Abu 2016-01-13

    Ran on both Alloy and Classic app. No issues.
  8. Mauro Piccotti 2016-02-23

    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.
  9. Joshua Quick 2018-06-12

    Ticket [TIMOB-25231] will resolve this issue. This fix is scheduled to be in Titanium 7.3.0.

JSON Source