1 cordova.define("cordova-plugin-file.DirectoryReader", function(require, exports, module) { /*
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
22 var exec = require('cordova/exec'),
23 FileError = require('./FileError') ;
26 * An interface that lists the files and directories in a directory.
28 function DirectoryReader(localURL) {
29 this.localURL = localURL || null;
30 this.hasReadEntries = false;
34 * Returns a list of entries from a directory.
36 * @param {Function} successCallback is called with a list of entries
37 * @param {Function} errorCallback is called with a FileError
39 DirectoryReader.prototype.readEntries = function(successCallback, errorCallback) {
40 // If we've already read and passed on this directory's entries, return an empty list.
41 if (this.hasReadEntries) {
46 var win = typeof successCallback !== 'function' ? null : function(result) {
48 for (var i=0; i<result.length; i++) {
50 if (result[i].isDirectory) {
51 entry = new (require('./DirectoryEntry'))();
53 else if (result[i].isFile) {
54 entry = new (require('./FileEntry'))();
56 entry.isDirectory = result[i].isDirectory;
57 entry.isFile = result[i].isFile;
58 entry.name = result[i].name;
59 entry.fullPath = result[i].fullPath;
60 entry.filesystem = new (require('./FileSystem'))(result[i].filesystemName);
61 entry.nativeURL = result[i].nativeURL;
64 reader.hasReadEntries = true;
65 successCallback(retVal);
67 var fail = typeof errorCallback !== 'function' ? null : function(code) {
68 errorCallback(new FileError(code));
70 exec(win, fail, "File", "readEntries", [this.localURL]);
73 module.exports = DirectoryReader;