My aim is to create a folder like "/sdcard/files/excel/" or "/sdcard/files/pdf/". The part after sdcard
comes from an url("/files/excel"). So first I want to check whether "/files/excel" exists, then create a file if it does not also exist. The name comes from url called "localFileName".
In this case folder="files/excel" and localFileName="Sheet1.html".
After the fs.root.getDirectory line I got Error 12 called FileError.PATH_EXISTS_ERR but there is no folder or file in 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);
There is a simple file manager for cordova-phoengap:
https://github.com/torrmal/cordova-simplefilemanagement
You can recursively create directories:
//CREATE A DIRECTORY RECURSIVELY
new DirManager().create_r('folder_a/folder_b',Log('created successfully'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With