9

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);
dda
  • 6,030
  • 2
  • 25
  • 34
engincancan
  • 2,442
  • 2
  • 28
  • 43
  • I find the solution my self at the answer of @dhaval at this [link](http://stackoverflow.com/questions/10961000/nested-directory-creator-phonegap) so here is my code `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);` I used the create directory method of @dhaval 's – engincancan Jan 25 '13 at 13:21

1 Answers1

1

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'));
Jorge Torres
  • 271
  • 3
  • 2