I'd like to use Cordova api to get a list of files in a folder.
dir.rootDir="a2015/";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0
, function(fileSystem){
dir.root=fileSystem.root;
// Create without folder
dir.root.getDirectory(dir.rootDir, {create:true, exclusive:false}, function(success){}, fail);
// Using the createReader method of the dir object,
// Create a DirectoryReader Object to Load Files in a Directory
vardirectoryReader=dir.root.createReader();
// Read the entries in the directory and pass them to the callback function as an array.
directoryReader.readEntries(function(success){
dir.files=success;
});
}
);
What should I do if I want to list the files in a2015/ that will be created?Thank you for your cooperation.
monaca cordova
I think the objects that should generate DirectoryReader are different.
dir.rootDir="a2015/";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSystem){
dir.root=fileSystem.root;
// Create without folder
dir.root.getDirectory(dir.rootDir, {create:true, exclusive:false},
function(d){
// Use the createReader method of the d object.
// Create a DirectoryReader Object to Load Files in a Directory
vardirectoryReader=d.createReader();
// Read the entries in the directory and pass them to the callback function as an array.
directoryReader.readEntries(function(success){
dir.files=success;
});
},
function(err){}
);
}
);
© 2025 OneMinuteCode. All rights reserved.