嵌套目录创建者:Phonegap

编程入门 行业动态 更新时间:2024-10-23 02:07:59
本文介绍了嵌套目录创建者:Phonegap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用此API在Phonegap中创建嵌套目录?

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()); }

有关完整示例,请检查此 gist

For full example check this gist

更多推荐

嵌套目录创建者:Phonegap

本文发布于:2023-11-28 16:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643208.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建者   嵌套   目录   Phonegap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!