Home arrow Flash arrow A Closer Look at Apollo`s File System API
FLASH

A Closer Look at Apollo`s File System API


In this second article in a two-part series devoted to Apollo's file system API, we delve heavily into the intricacies of creating and manipulating files and directories. It is excerpted from chapter four of the Apollo for Adobe Flex Developer's Pocket Guide, written by Mike Chambers, Rob Dixon and Jeff Swartz (O'Reilly, 2007; ISBN: 0596513917). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
March 20, 2008
TABLE OF CONTENTS:
  1. · A Closer Look at Apollo`s File System API
  2. · Copying and Moving Files and Directories
  3. · Reading and Writing Files
  4. · The open() and openAsync() Methods
  5. · File Open Modes

print this article
SEARCH DEVARTICLES

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.

Also see “Getting a Directory Listing” inChapter 5.

Getting File Information

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.

modificationDate

The date when the file was last modified.

name

The file or folder name.

size

The size of the file, in bytes.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials