Hui Zhou
Hui Zhou

Reputation: 45

How to get all files for a directory including all subdirectories with HTML5

In HTML5, we can create a reader on a DirectoryEntry to list all the files and folders for that folder. But I want to get all the files for a directory including all subdirectories, does anyone has any idea?

Upvotes: 0

Views: 271

Answers (1)

user1987480
user1987480

Reputation: 83

Sorry for the long delay, to get all files for a directory including all subdirectories, use this:

var numDirs = 0;
var numFiles = 0;
function loadDirEntry(_chosenEntry) {
    var directoryReader = _chosenEntry.createReader();
    directoryReader.readEntries(readerSuccess, errorHandler);
}
function readerSuccess(entries) {
    var i;
    for (i = 0; i < entries.length; i++) {
        if (entries[i].isFile === true) {
            numFiles++;
            displayFiles(entries[i]);
        } else if (entries[i].isDirectory === true) {
            numDirs++;
            loadDirEntry(entries[i]);
        }
    }
} 

Hope this help!

Upvotes: 1

Related Questions