您的位置:首页 > 编程语言

【web】一段创建本地文件夹的代码

2016-11-02 16:00 274 查看
一段创建本地文件夹的代码

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("文档中心===========>软件准备就绪:设置检测文件存储目录结束");

        };

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

这是跨平台的创建文件夹,不像android那样还要通过 Environment.getExternalStorageDirectory() 的原生代码来创建
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐