A Closer Look at Apollo`s File System API (Page 1 of 5 )
Reading Directory Contents
The File.listDirectory() method returns an array listing ofFileobjects that represent the files and directories contained within the specified directory. For example, the following code lists the contents of the desktop directory:
var directory:File = File.desktopDirectory; var contents:Array = directory.listDirectory(); for (var i:uint = 0; i < contents.length; i++) { if (contents[i].isDirectory) { trace(contents[i].name); } else { trace(contents[i].name, contents[i].size, "bytes"); } }
TheFile.listDirectory()method returns only the root level files and directories in a directory. It does not recursively search through subdirectories for their contents. You can, of course, write code to traverse subdirectories, though if you do so, you might want to use theFile.listDirectoryAsync()method so that other ActionScript-driven processes can continue while the directory listings are being compiled.
The File class includes a number of properties that contain information about a file or directory.
Property
Description
exists
States whether the file or directory exists. This is worth checking, for example, before you attempt to read, write, copy, or move a file.
isDirectory
States whether the Fileobject points to a directory (true) or a file (false). You will want to check this before attempting directory-specific operations (such as the listDirectory() method) or attempting file-specific operations (such as reading a file).
isHidden
States whether the file or directory is hidden.
nativePath
Notes the operating system-specific path to the file or directory.
parent
Notes the parent directory of the File instance.
url
Notes the operating system-independent path to the file or directory.
TheFileclass also inherits the following useful properties from theFileReferenceclass:
Property creationDate
Description The date the file or folder was created.