F***@163.com
F***@163.com
  • 发布:2019-01-16 11:35
  • 更新:2020-05-07 21:37
  • 阅读:2094

关于使用 DirectoryEntry 对象创建文件和目录出现的问题。

分类:HTML5+
IO

我使用 DirectoryEntry 对象的 getDirectory 和 getFile 方法创建,都会生成在使用 DirectoryEntry 对象的父路径中。

比如说,我用 resolveLocalFileSystemURL 进入 /sdcard/Images 目录,获取到了目录的 DirectoryEntry 对象。
然后,我调用此对象 getFile("a.txt", { create: true, exclusive: true }, fun, fun) 创建 a.txt, 结果却是 /sdcard/a.txt 而不是 /sdcard/Images/a.txt。
我试过修改 a.txt 为 ./a.txt (使用相对路径) 和 entry.fullPath "/a.txt" (使用绝对路径).
相对路径情况结果一致, 使用绝对路径会创建成功,但是在程序文件目录。

创建代码如下:

// 新建  
// type: "file" | "folder" 要创建的资源类型  
// file: string 创建的资源名称  
onNew: function (type, file) {  
    // 确定调用的创建方法  
    var method = type !== "file" ? "getDirectory" : "getFile";  
    var self = this;  
    // 当前目录的 DirectoryEntry  
    var parent = this.list[0].entry;  
    // 测试绝对路径的情况下使用  
    var path = parent.fullPath;  
    if (!/\/$/.test(path)) {  
        path = path   "/";  
    }  
    console.log(this.list[0].entry.fullPath   "  "   method   "  "   "./" file);  
    // 执行创建  
    parent[method]("./" file, { create: true, exclusive: true },  
        function (entry) {  
            mui.toast("创建成功 !");  
            console.log("创建成功: "  entry.fullPath);  
        }, function (error) {  
            mui.toast("创建失败 !");  
            self.onError(error);  
        });  
},

请问怎样实现将 text.txt 创建在 /sdcard/Images/text.txt, 而不是 /sdcard/text.txt.
谢谢 !

2019-01-16 11:35 负责人:无 分享
已邀请:
东庐

东庐

解决了吗?我也遇到这个问题了

helloworid

helloworid - 能一起学习吗?我qq:3215636570

。。。。。

9***@qq.com

9***@qq.com

怎么样,已经2020年了,有解决啊

该问题目前已经被锁定, 无法添加新回复