6 Replies Latest reply on Jan 5, 2010 3:10 PM by Joe ... Ward

    determining when directory listing is done...

    GapingWound

      I have a recursive directory listing function that parses a media directory for music files, and I'm using getDirectoryListingAsync. The function writes the full path names of the music files to a text file in the applicationStorageDirectory for later processing. What I need to do now is determine when the function is "done" reading so I can start inserting the resulting list into a database.

      I have tried adding an event listener for air.Event.CLOSE and for air.Event.COMPLETE but neither seems to fire. How can I tell when it's done parsing the directory?

       

      EDIT: Sorry, forgot to mention that I'm using HTML/Ajax, though I'd be willing to use Flex if that would be more appropriate.

       

      Thanks,

      Keith

        • 2. Re: determining when directory listing is done...
          GapingWound Level 1

          Right, and I'm using that, because I wouldn't be able to get the file list without it. What I'm looking for is a way to tell when my recursive directory parser function is done. Ie., it's walked the entire directory structure and there are no more subdirectories to parse or files to list.

           

          I may not have described my problem in enough detail, so I'll try it again.

           

          I'm writing a touchscreen mp3 jukebox. The jukebox will use a sqlite db to store basic data for the media library. In order to do that, I have to do the following:

          1. Have the user select the location of their media library. This is done.

          2. Recursively walk the directory, and store all the file names in a text file. This is the part I'm having trouble with.

          3. Once I have the list of files, I can use it to grab the id3 data and store it in the database. This is done.

           

          I have tried writing a monolithic function that recursively walks the media directories and stores all the data in the database all at once, the problem is that for libraries of more than a few hundred files, this locks up the program for the duration, and often will simply crash, and even then, I STILL have no way to know when the recursive function is done so I can jump into the main functionality of the jukebox.

          So I decided to write it in several parts.

          The first part is to walk the media directory and write the full path name of every media file to a text file that I can later process. That all works fine, except that I cannot tell when it's done parsing the directory.

          The docs state that the air.Event.COMPLETE fires when async operations are finished, but that apparently doesn't apply to getDirectoryListingAsync();

           

          What I'm looking for is some way to determine when the function is complete. Some insight that others have discovered when thay ran into this same problem (I can't be the first).

           

          I have tried incrementing a counter when a new directory is encountered and then decrementing it when directoryListingComplete fires, in the hopes that it would be >0 while the function was running and <=0 when it was done, but it somehow ends up at -1 when it switches between directories in the main directory root.

           

          None of the recursive directory listing examples I have seen address this issue and it's been frustrating. I would be done with this project by now if not for this one seemingly simple problem.

          • 3. Re: determining when directory listing is done...
            Joe ... Ward Level 4

            In this case, getDirectoryAsync() has a more specific event than "complete." You get a directoryListing event for each call to getDirectoryAsync(). What more do you want? How do you expect the runtime to know when your code is done looking at directories?

             

            A technique I've used is:

            Get a directory listing

                 For each File

                      if file, then store it

                      if directory, then push it into an array

                 Dispatch a progress event

             

            On progress event

                 If directory array is empty, dispatch (my own) complete event

                 Else pop a directory from the array and repeat above.

             

            On complete event

                 We're done here.

             

            By processing one directory at a time and dispatching an event to trigger the next processing step, you let the UI code get some time to update so your application doesn't become unresponsive. If the time to process the files in a single directory is still too long, you would have to add another layer so that you only process a limited number of files during each processing step.

            1 person found this helpful
            • 4. Re: determining when directory listing is done...
              GapingWound Level 1

              THAT is the kind of info I was looking for. I guess the logical course of action for me now would be to research dispatching my own events

               

              Thanks,

              Keith

              • 5. Re: determining when directory listing is done...
                Joe ... Ward Level 4

                I wrote a "quick start" article that, among other things, demonstrates how to dispatch events in an HTML-based AIR application:

                 

                http://www.adobe.com/devnet/air/ajax/quickstart/creating_toast-style_windows.html

                 

                The section about events is at the end of the article.

                1 person found this helpful
                • 6. Re: determining when directory listing is done...
                  GapingWound Level 1

                  Thanks for all the help, I'll take a look when I get home this evening.