【发布时间】:2013-01-24 12:07:09
【问题描述】:
我的目标是创建一个像“/sdcard/files/excel/”或“/sdcard/files/pdf/”这样的文件夹。 sdcard 之后的部分来自一个 url("/files/excel")。所以首先我想检查“/files/excel”是否存在,如果不存在则创建一个文件。该名称来自名为“localFileName”的url。
在本例中是 folder="files/excel" 和 localFileName="Sheet1.html"。
在 fs.root.getDirectory 行之后,我得到了名为 FileError.PATH_EXISTS_ERR 的错误 12 但 sdcard 中没有文件夹或文件。
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
var folder = file_path.substring(0,file_path.lastIndexOf('/'));
console.log(folder);
fs.root.getDirectory(folder,{create: true, exclusive: false},function (datadir) {
console.log(folder);
datadir.getFile(localFileName, {create: true, exclusive: false},function(fileEntry) {
var ft = new FileTransfer();
yol = "/sdcard/"+folder+localFileName;
ft.download( remoteFile,yol,function(entry) {
console.log(entry.fullPath);
}, fail);
}, fail);
}, fail);
}, fail);
【问题讨论】:
-
我在@dhaval 在这个link 的答案中找到了我自己的解决方案,所以这是我的代码
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) { window.FS = fileSystem; var printDirPath = function(entry){ console.log("Dir path - " + entry.fullPath);} createDirectory(folder,localFileName,remoteFile, printDirPath); }, fail);我使用了@dhaval 的创建目录方法