0

这应该很简单,但我就是无法让它工作

Szenario: 我想使用 phonegap 文件 API 遍历我的文件夹

问题: 我无法让 getDirectory() 函数正常工作

非常简单的例子:(为了说明我的问题)

var fileSystem, basePath;

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, doStuff, function(error) { 
    notificationservice.log('Failed to get local filesystem: ' + error.code); 
});

function doStuff(fs) {
    fileSystem = fs;
    basePath = fileSystem.root.fullPath;

    var directoryEntry = new DirectoryEntry('', basePath);
    readDirectory(directoryEntry);
}

function readDirectory(directoryEntry) {
    var directoryReader = directoryEntry.createReader();
    directoryReader.readEntries(function(entries) {
        for (var i = 0 ; i < entries.length ; i++) {
            notificationservice.log(entries[i].fullPath);

            fileSystem.root.getDirectory(entries[i].fullPath, {create: false}, function(dir) {
                    notificationservice.log('SUCCESS');
                }, function (error) { 
                    notificationservice.log('Failed to get directory'); 
                });

        }
    }); 
}       

我可以使用 访问我的文件夹,new DirectoryEntry()但是每当我尝试使用该getDirectory()功能访问目录时,我都会失败 - 如果有人可以帮助我更正上面的代码以便fileSystem.root.getDirectory()不会返回错误,我将非常感谢!

请注意:我使用 eclipse 编辑器进行部署并部署到 nexus 7(如果可能,代码应该可以在 iOS 等平台上运行,或者也可以运行)

谢谢,马蒂亚斯

顺便说一句:我确信有很多问题实际上可以解决这个问题 - 但是,我找不到任何对我有用的东西......

4

1 回答 1

0

根据https://meta.stackexchange.com/questions/17845/etiquette-for-answering-your-own-question

愚蠢的我 - 迷上了我从网上获得的脚本 - 我必须像这样使用 .name 属性(当前目录的相对路径)

fileSystem.root.getDirectory(name, {create: false}, function(dir) {...
- 这个问题已经解决(如果有人在这上面浪费时间,我很抱歉)

于 2013-06-17T22:27:57.047 回答