9

私の目的は、「/ 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);
4

1 に答える 1

1

cordova-phoengap 用のシンプルなファイル マネージャーがあります。

https://github.com/torrmal/cordova-simplefilemanagement

ディレクトリを再帰的に作成できます。

//CREATE A DIRECTORY RECURSIVELY

new DirManager().create_r('folder_a/folder_b',Log('created successfully'));
于 2014-04-05T17:05:51.963 に答える