Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

18. File > Reading Directory Entries

Reading Directory Entries

Once you have access to the file system (either through the persistent or temporary storage area), you have the ability to process directory entries using the File API’s DirectoryReader object. To create a DirectoryReader object, an application must make a call to createReader, as shown in the following function:

function onGetFileSystemSuccess(fs) {
  alert("Accessing " + fs.name + " storage (" +
    fs.root.fullPath + ")");
  //Create a directory reader we'll use to list the files in
  //the directory
  var dr = fs.root.createReader();
  // Get a list of all the entries in the directory
  dr.readEntries(onDirReaderSuccess, onFileError);
}

In this example, the call to createReader is made in the callback function executed after requesting a file system object as described in the previous section. Here the application uses the file system object to create a DirectoryReader pointing at the root folder of the selected file system. The DirectoryReader (dr in the example) supports only a single method, readEntries, which is used to read all of the entries in the specified folder.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint