6 Replies Latest reply on Aug 24, 2011 12:49 AM by Starlover_jacob

    problem with # (%23) in foldername

    Starlover_jacob Level 1

      Hi there,

       

      I have a backup script for my air application that creates a zip of all files inside applicationStorageDirectory.

      One of the folders inside that dir is called; #ApplicationUpdater

       

      For some reason the function that gets all filenames inside that folder stops to work.

      This works on a windows machine, but on a mac it simply stops.. no error nothing..

       

      Please some help.

       

      code:

       

      getlist=getdirlist(dirlist,foldername);
      
                  // used vars for getting a dirlist of the applicationstoragedir.
                  private var tempdirlist:Array;
                  private var foldername:String;
                  private var dirlist:Array=new Array();
                  // ATTENTION! RECURSIVE FUNCTION.
                  private function getdirlist(tempdirlist:Array,foldername:String):Array
                  {
                      // path to application storage dir.
                      var directory:File = File.applicationStorageDirectory;
                      if(foldername!=null)
                          directory=File.applicationStorageDirectory.resolvePath(unescape(foldername));
                      // gets a list of files and folders.
                      tempdirlist=directory.getDirectoryListing();
                      //run trough that list.
                      for (var i:uint = 0; i < tempdirlist.length; i++) 
                      {
                          // if you want to show folders in the dirlist array just turn of the following if statement.
                          if(tempdirlist[i].extension!=null)
                          {
                              var stringcut:String=tempdirlist[i].url;
                              dirlist.push(stringcut);
                          }
                          // if no extention is found it must be a folder, so we go into it by 
                          // calling this function and give that foldername with it.
                          //if(tempdirlist[i].extension==null)
                          else
                          {
                              foldername=tempdirlist[i].url;
                              getdirlist(tempdirlist,foldername);                        
                          }
                      }
                      return dirlist;
                  }
      
        • 1. Re: problem with # (%23) in foldername
          Flex harUI Adobe Employee

          Is there a reason you are calling unescape?

          • 2. Re: problem with # (%23) in foldername
            Starlover_jacob Level 1

            Hi,

             

            Well in my previous attempts i used tempdirlist[i].nativePath substracted some characters from it to let it work.. i then got the problem on windows with # so after some search i found that unescape could help.

             

            Well some programming days later.. i found out that saving a nativePath of an image to my sqlite db was not a succesfull idea. I needed to save url instead, so i can place a backup of my sqlite database and folder of images at any system.. and it would just work.

             

            so i also modified my backup to url instead of nativePath.. so the unescape was just a leftover of previous coding.. and it didn't seem to bother on a windows machine.. so i left it there.

             

            I removed it from the code and tested it again.. no difference what so ever.. it works on a windows machine.. still not on a mac.

             

            Any ideas?

            • 3. Re: problem with # (%23) in foldername
              Flex harUI Adobe Employee

              When you debug through it, do you not get a valid directory or is

              tempDirList null?

              • 4. Re: problem with # (%23) in foldername
                Starlover_jacob Level 1

                Hi,

                 

                when i do:

                tempdirlist=directory.getDirectoryListing();
                Alert.show(""+tempdirlist.length);

                it outputs 5, so he thinks there are 5 items in my applicationStorageDirectory

                 

                When i look at my folder structure there are the following files/folders:

                #ApplicationUpdater (folder)

                imagesfolder (folder)

                imagesfolder2 (folder)

                imagesfolder3 (folder)

                mydatabase.db (file)

                 

                so 5 is correct.

                Now i run trough that tempdirlist

                for (var i:uint = 0; i < tempdirlist.length; i++)
                                {
                                    // if you want to show folders in the dirlist array just turn of the following if statement.
                                    Alert.show(""+tempdirlist[i].url);

                 

                the alert shows me: app-storage:/%23ApplicationUpdater

                 

                since there is no extension it should be a folder, so i call the same function with that folder name.. in this case app-storage:/%23ApplicationUpdater

                Now it should run to the same alert where i get a numer of items inside that applicationupdater folder.

                I do not get an alert.. so directory=File.applicationStorageDirectory.resolvePath(foldername); failed

                 

                Is there a way to alert all given errors? since i develop on a windows machine export my project and test it on a mac.. i cannot debug on a mac. Only by showing stuff by using alert or put it in textarea.

                 

                Greets, J.

                • 5. Re: problem with # (%23) in foldername
                  Flex harUI Adobe Employee

                  According to the doc, you should not use URLs in resolve path, try using the

                  nativePath instead

                  • 6. Re: problem with # (%23) in foldername
                    Starlover_jacob Level 1

                    Thank you.. it indeed were that simple.

                     

                    Beneith the correct function to get a dirlist from the applicationStorageDirectory.

                     

                    I cut the first part of the string, to get a list of folder/filename items and not the complete nativepath.

                    This way.. when i need to read that files for lets say creating a zip. I can use; var thisfile:File =File.applicationStorageDirectory.resolvePath(getlist[1]);

                     

                                private var tempdirlist:Array;
                                private var foldername:String;
                                private var dirlist:Array=new Array();
                    
                                // ATTENTION! RECURSIVE FUNCTION.
                                private function getdirlist(tempdirlist:Array,foldername:String):Array
                                {
                                    // path to application storage dir.
                                    var directory:File = File.applicationStorageDirectory;
                                    if(foldername!=null)
                                        directory=File.applicationStorageDirectory.resolvePath(foldername);
                                    // gets a list of files and folders.
                                    tempdirlist=directory.getDirectoryListing();
                                    //run trough that list.
                                    for (var i:uint = 0; i < tempdirlist.length; i++) 
                                    {
                                        // if you want to show folders in the dirlist array just turn of the following if statement.
                                        if(tempdirlist[i].extension!=null)
                                        {
                                            var stringcut:String=tempdirlist[i].nativePath;
                                            var fulllength:Number=stringcut.length;
                                            var lengthToSubstract:String = File.applicationStorageDirectory.nativePath;
                                            
                                            stringcut=stringcut.substr(lengthToSubstract.length+1,fulllength);
                                            dirlist.push(stringcut);
                                        }
                                        // if no extention is found it must be a folder, so we go into it by 
                                        // calling this function and give that nativePath to that folder with it.
                                        else
                                        {
                                            var newfoldername:String=tempdirlist[i].nativePath;
                                            getdirlist(tempdirlist,newfoldername);                        
                                        }
                                    }                
                                    return dirlist;
                                }
                    
                    var getlist:Array;
                    getlist=getdirlist(dirlist,foldername);