Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
File API | 91

catch( ioe )
{
alert( "Could not move temporary file:\n" + ioe.message );
}
}
</script>

</head>
<body onload="doLoad( )">

</body>
</html>

Iterate the Contents of a Directory


Problem


The application is required to display information about a
directory as part of the user interface.


Solution


Use theFile.browseForDirectoryAPI to prompt the user to
select a directory, and then use theFile.listDirectoryAPI
to iterate through the contents of the directory.


Discussion


The File class provides numerous properties that can be used
to get specific information about files on disk. There are also
two methods on the File class that pertain to getting a direc-
tory list. The first is theFile.browseForDirectory( ), which
can be used to prompt the user to select a directory using the
native dialog. The second is the File.listDirectory( )
method, which will return an array ofFileobjects for the
currently referenced directory.


Before prompting the user to select a directory using the
native dialog, the application needs to establish and register
an event handler for Event.SELECT. The Event.target

Free download pdf