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.
1 person found this helpful
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.
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
1 person found this helpful
I wrote a "quick start" article that, among other things, demonstrates how to dispatch events in an HTML-based AIR application:
The section about events is at the end of the article.
Thanks for all the help, I'll take a look when I get home this evening.