我的目标是创建一个文件夹,例如“/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);
最佳答案
有一个用于cordova-phoengap的简单文件管理器:
https://github.com/torrmal/cordova-simplefilemanagement
您可以递归创建目录:
//CREATE A DIRECTORY RECURSIVELY
new DirManager().create_r('folder_a/folder_b',Log('created successfully'));
关于file - Phonegap : Create a file in a specific folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14501000/