File 无法通过getDirectory()函数访问phonegap中的任何目录
这应该很简单,但我就是不能让它工作 Szenario: 我想用phonegap文件API遍历我的文件夹 问题: 我无法使getDirectory()函数正常工作 非常简单的示例:(用于说明我的问题)File 无法通过getDirectory()函数访问phonegap中的任何目录,file,cordova,File,Cordova,这应该很简单,但我就是不能让它工作 Szenario: 我想用phonegap文件API遍历我的文件夹 问题: 我无法使getDirectory()函数正常工作 非常简单的示例:(用于说明我的问题) var文件系统,basePath; requestFileSystem(LocalFileSystem.PERSISTENT,0,doStuff,函数(错误){ notificationservice.log('获取本地文件系统失败:'+错误代码); }); 函数doStuff(fs){ 文件系统=
var文件系统,basePath;
requestFileSystem(LocalFileSystem.PERSISTENT,0,doStuff,函数(错误){
notificationservice.log('获取本地文件系统失败:'+错误代码);
});
函数doStuff(fs){
文件系统=fs;
basePath=fileSystem.root.fullPath;
var directoryEntry=新的directoryEntry(“”,basePath);
readDirectory(directoryEntry);
}
函数readDirectory(directoryEntry){
var directoryReader=directoryEntry.createReader();
directoryReader.readEntries(函数(条目){
对于(变量i=0;i
我可以使用newdirectoryentry()
访问我的文件夹,但每当我尝试使用getDirectory()
函数访问目录时,我都会失败-如果有人能帮我更正上述代码,以便fileSystem.root.getDirectory()
不会返回错误,我将非常感谢
请注意:
我使用eclipse编辑器进行部署并部署到Nexus7
(如果可能的话,代码应该在iOS或win等平台上运行)
谢谢,
马蒂亚斯
顺便说一句:我确信有很多问题可以真正解决这个问题——然而,我还没有找到任何适合我的东西……根据
愚蠢的我-被我从网上得到的脚本迷住了-我必须使用.name属性(当前目录的相对路径),就像这个fileSystem.root.getDirectory(name,{create:false},function(dir){…-这个问题已经解决了(如果有人在这个问题上浪费时间,我很抱歉)
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');
});
}
});
}
fileSystem.root.getDirectory(name, {create: false}, function(dir) {...