PDA

View Full Version : for loop dir


davej
02-16-2009, 06:16 PM
Hi All
I am having a very weird issue. I am trying to loop through some directories and sub directories. I have that working. the problem is the way it outputs the results. its basically a nested loop so it should trace each top loop and then then results for each nested loop for the iteration of the top loop. However it does not it traces out all the top level loop then all the nested loop. Goes against all logic and every nested loop I have ever done. any suggestions to get this working would be great.


var directory:File=File.desktopDirectory;
directory.getDirectoryListingAsync();
directory.addEventListener(FileListEvent.DIRECTORY _LISTING, directoryListingHandler);

function directoryListingHandler(event:FileListEvent):void {
var list:Array=event.files;
for (var i:uint = 0; i < list.length; i++) {
if (list[i].name=="panelMover") {
if (list[i].extension==null) {
trace(list[i].nativePath);
var subDir:File=list[i];
subDir.getDirectoryListingAsync();
subDir.addEventListener(FileListEvent.DIRECTORY_LI STING, subDirListingHandler);
function subDirListingHandler(event:FileListEvent):void {
var list:Array=event.files;
for (var i:uint = 0; i < list.length; i++) {
trace("a");
fileContents_txt.appendText( list[i].name+"\n");
var conDir:File=list[i];
conDir.getDirectoryListingAsync();
conDir.addEventListener(FileListEvent.DIRECTORY_LI STING, conDirListingHandler);
function conDirListingHandler(event:FileListEvent):void {
var list:Array=event.files;
for (var i:uint = 0; i < list.length; i++) {
trace("b");
//trace( list[i].nativePath)
fileContents_txt.appendText( list[i].name+"\n");
}
}
}

}
}

}
}
}