|
通过file API创建文件后,再通过file的list接口查询出所有文件,并遍历删除,在删除动作均触发success回调的情况下,再次通过list接口查询,发现文件数量不变,即表现为没有被删除。
主要代码如下:
- clickMe2(){
- console.log("ssssssssss");
- this.title="AAAAA"
- this.num =100;
- this.delNum=0;
- let that = this;
- let max = 100;
- for(let i=0;i<max;i++){//循环创建100个文件
- let f = "internal://files/tdlog/file_"+i;
- file.writeText({
- uri:f,
- text:"ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt",
- success:function(){
- that.title=f
- console.log("event saved success:"+f);
-
- },
- fail:function(){
- console.log("write failed:"+f);
- }
- })
- }
- setInterval(function(){//定时遍历文件,记录文件数,并遍历删除
- file.list({
- uri:"internal://files/tdlog/",
- success:function(data){
- let fileList = data.fileList;
- console.log("list file:"+fileList.length);
- that.num =fileList.length;//此处获取到的文件数量一直为100,
- fileList.forEach(function(f){
- file.delete({
- uri:f.uri,
- success:function(){
- that.delNum = that.delNum+1;
- console.log("delete file success:"+f.uri);//触发删除成功的回调
- },
- fail:function(){
- console.log("delete file failed:"+f.uri);
- }
- })
- })
- }
- })
- },5000);
-
-
- }
复制代码
|
|