0 Replies Latest reply on Jul 27, 2011 7:46 AM by The ock

    Recursive "getDirectoryListing()"

    The ock

      Hi

      i'm try to create a music player application that will enable a user to select a directory, then get the files in the selected directory, insert then into a playlist array, then pick each song one by one and then play them, my code looks like this;

      var __files:File = new File();

      var songArray:Array = new Array();

       

       

      try
      {
          __files.browseForDirectory("Select Directory");
          __files.addEventListener(Event.SELECT, directorySelected);
      }
      catch (error:Error)
      {
          trace("Failed:", error.message);
      }

      function directorySelected(event:Event):void
      {
          
          __files = event.target as File;
          var files:Array = __files.getDirectoryListing();
          for(var i:uint = 0; i < files.length; i++)
          {
           //check if the song is an mp3 file
             if(String(files[i].nativePath).search(".mp3") != -1)
              {
                  songArray.push(files[i].nativePath);
              }
          }
      }

      this works very fine. but what if the selected folder also contain sub-folders that has song files in it, how
      do i also search the sub-folders and retrieve the song files.
      thanks for your help.