web 开发之创建本地文件夹的实现方法

时间:2019-03-30
本文章向大家介绍web 开发之创建本地文件夹的实现方法,主要包括web 开发之创建本地文件夹的实现方法使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

web 开发之创建本地文件夹的实现方法

 filemanage_util.fullPath 就是创建文件的路径

这是跨平台的创建文件夹,不像Android那样还要通过 Environment.getExternalStorageDirectory() 的原生代码来创建

实现代码:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
      // alert('ondeviceReady');
      // window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
      console.log("文档中心===========>软件准备就绪:设置检测文件存储目录开始.");
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
        console.log("文档中心===========>检测临时文件存储目录方法");
        //util.appRootDirName 全局变量,这里是zgky
        fileSystem.root.getDirectory(filemanage_util.appRootDirName, {
          create: true,
          exclusive: false
        }, function (entry) {
          //网上流传的资料中都是使用fullPath,在这里我获取到的是相对目录,在下载时使用会报错,所以换做了toURL()
          //这是一个全局全局变量,用以保存路径
          console.log("文档中心===========>创建文件夹成功,正在设置相关的参数!");
          filemanage_util.fullPath = entry.toURL();
          // alert(util.fullPath);
          console.log("文档中心===========>创建文件夹成功:" + filemanage_util.fullPath);
          //console.log(util.fullPath);
        }, function () {
          console.log("文档中心===========>创建文件夹失败!");
        });
        console.log("文档中心===========>检测临时文件目录方法结束!");
      }, function () {
        console.log("文档中心===========>创建文件夹失败");
      });
      console.log("文档中心===========>软件准备就绪:设置检测文件存储目录结束");
    };

以上就是web创建本地文件夹的实现方法,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!