嵌套目录的创造者:PhoneGap的 [英] Nested directory creator: Phonegap

查看:101
本文介绍了嵌套目录的创造者:PhoneGap的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能创建PhoneGap的嵌套目录与API?

How can I create a nested directory in Phonegap with this API?

fileSystem.root.getDirectory("Android/data/com.phonegap.myapp/dir_one/dir_two/", {create:true}, gotDir, onError);

我在Android 2.2的使用PhoneGap的1.8.0。

I am using Phonegap 1.8.0 in Android 2.2.

推荐答案

此功能将帮助您创建嵌套显示目录。

This function will help you create nested dirs.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log("device is ready");
    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function fail() {
    console.log("failed to get filesystem");
}

function gotFS(fileSystem) {
    window.FS = fileSystem;

    var printDirPath = function(entry){
        console.log("Dir path - " + entry.fullPath);
    }

    createDirectory("dhaval/android/apps", printDirPath);
    createDirectory("this/is/nested/dir", printDirPath);
    createDirectory("simple_dir", printDirPath);
}

function createDirectory(path, success){
    var dirs = path.split("/").reverse();
    var root = window.FS.root;

    var createDir = function(dir){
        console.log("create dir " + dir);
        root.getDirectory(dir, {
            create : true,
            exclusive : false
        }, successCB, failCB);
    };

    var successCB = function(entry){
        console.log("dir created " + entry.fullPath);
        root = entry;
        if(dirs.length > 0){
            createDir(dirs.pop());
        }else{
            console.log("all dir created");
            success(entry);
        }
    };

    var failCB = function(){
        console.log("failed to create dir " + dir);
    };

    createDir(dirs.pop());
}

有关完整的例子检查这要点

For full example check this gist

这篇关于嵌套目录的创造者:PhoneGap的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆