1 Reply Latest reply on Aug 22, 2011 3:37 AM by Starlover_jacob

    How to find installed assets on mac in applicationdirectory

    Starlover_jacob Level 1

      Hi,

       

      File.applicationDirectory—the read-only directory where the application is installed (along with any installed assets)

       

      How do i get to this assets folders/files on a mac?

       

      I tried the following, but i don't get a list of files.... it works on a windows machine..

       

      structure:

      myapp.air

      assets/folder1/img1.jpg

      assets/follder1/img2.jpg

      assets/folder2/anotherimage.jpg

       

       

       

      urlarray:Array=getallfilesinfolder(folder1);

      public function getallfilesinfolder(foldername:String):Array {      var filearray:Array=new Array();      var directory:File = File.applicationDirectory;      directory = directory.resolvePath("assets/"+foldername+"");      var contents:Array = directory.getDirectoryListing();      for (var i:Number = 0; i < contents.length; i++)      {             if(contents[i].type==".jpg" ||contents[i].type==".JPG" || contents[i].type==".png")             filearray.push(contents[i].url);      }                    return filearray; }

       

       

      Please some help.

       

      Perhaps you also know a solution for folders that begin wit a # (%23).

      When i want to get a filelist from that folder, the function simply stops on a mac. no error... nothing

        • 1. Re: How to find installed assets on mac in applicationdirectory
          Starlover_jacob Level 1

          Hi, i found my answer.

           

          It turns out that mac doesn't use type. Instead i had to check on extension

          contents[i].extension=="jpg"

           

           

          How i found out? to alert some variables like this.

          first i checked if the folder assets/folder1 exists

           

          import mx.utils.ObjectUtil;
          var directory:File = File.applicationDirectory;
          directory = directory.resolvePath("gardenimages/"+foldername+"");
          Alert.show("test:"+ObjectUtil.toString(directory));
          
          

          It will get you a long list of info on the folder. by checking the nativepath, url and exists we can tell if the folder is there.

           

          Now check the contents of that folder to see if the images are there.

           

          var contents:Array = directory.getDirectoryListing();
          var sTemp:String = "";
          for (var i2:int=0;i2<contents.length;i2++) 
          {
                 sTemp += contents [i2].name + "\n";
                 sTemp += contents [i2].exists + "\n";
                 sTemp += contents [i2].nativePath + "\n";
                 sTemp += contents [i2].url + "\n";
                 sTemp += contents [i2].type + "\n";
                 sTemp += contents [i2].extension + "\n";
                 sTemp += "----------- \n";
          }  
          

           

          and you will see.. on a mac type is null

           

           

          Greets, J.