Phonegap File API清空文件夹

时间:2014-08-11 18:16:31

标签: android cordova

仔细检查...如果标志“create”设置为true而“exclusive”设置为false, 这会基本上清空同一路径上的现有文件夹或文件吗?

所以说我有一个目录

>myDir
    >subDirectory
        -subFile
    -myFile

我跑

entry.getDirectory("myDir", {create: true, exclusive: false}, success, fail);

是清除myDir内容的首选方法

>myDir
   [empty]

1 个答案:

答案 0 :(得分:0)

如果文件夹已存在,则将create标志设置为false不应清空其中的文件。从目录中删除所有内容的首选方法是使用dirEntry.removeRecursively(successCallback, opt_errorCallback);

发布here on html5rocks.com的示例提出了这种方法:

window.requestFileSystem(window.TEMPORARY, 1024*1024, function(fs) {
  fs.root.getDirectory('/misc/../music', {}, function(dirEntry) {

    dirEntry.removeRecursively(function() {
      console.log('Directory removed.');
    }, errorHandler);

  }, errorHandler);
}, errorHandler);