我正在使用 Phonegap/Cordova 2.2
我正在尝试读取子目录的内容,但不知道该怎么做。
这是我的代码:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
function onFileSystemSuccess(fileSystem) {
var tmpPath = "dir1/dir2/";
fileSystem.root.getDirectory(tmpPath, {create: false, exclusive: false}, getDirSuccess, fail);
}
function getDirSuccess(dirEntry) {
// Get a directory reader
var directoryReader = dirEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(readerSuccess,fail);
}
如果我只获取一个目录路径那么它可以工作,如果我尝试获取一个包含两个目录的路径它会失败。
如有任何帮助,我们将不胜感激。
谢谢
最佳答案
你可以这样做:
function onFileSystemSuccess(fileSystem) {
var tmpPath = filesystem.root.fullPath + "/dir1/dir2";
window.resolveLocalFileSystemURI(tmpPath, getDirSuccess, fail);
}
但我很好奇为什么您显示的代码不起作用。您在什么平台上进行测试?
关于javascript - Phonegap - 读取子目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13613915/