如何创建目录中的文件夹在iphone和android [英] How to create folder in directory in iphone and android
问题描述
你能告诉我如何创建文件夹在目录中的android(SDCard)和IOS.?我还需要计数在同一目录中的文件夹数。
我有目录File:// SDCard / test。这里一个一个创建文件夹。在应用程序启动时,我需要计算dame目录中的文件夹数。
can you please tell me how to create folder in directory in android (SDCard) and in IOS.?I also need to count number of folder in same directory. I have directory File://SDCard/test . here one by one create folder .During application launch i need to count number of folder in dame directory .
什么是IPhone的目录?
What is directory of IPhone ?
推荐答案
查看 Cordova File API ,它基于W3C File API。它用于读取,写入和浏览文件系统层次结构。
Take a look at the Cordova File API which is based on the W3C File API. It is used to read, write and navigate file system hierarchies.
列出文件和文件夹
要列出/计数目录中的列表和文件,您必须使用 DirectoryReader
对象。
In order to list/count the lists and files inside a directory you have to use the DirectoryReader
object.
平台:
- Android
- BlackBerry WebWorks(OS 5.0及更高版本)
- iOS
- Windows Phone 7和8
- Windows 8
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- iOS
- Windows Phone 7 and 8
- Windows 8
例如:
function success(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
}
}
function fail(error) {
alert("Failed to list directory contents: " + error.code);
}
// Get a directory reader
var directoryReader = dirEntry.createReader();
// Get a list of all the entries in the directory
directoryReader.readEntries(success,fail);
创建目录
要创建目录,您必须使用 DirectoryEntry
对象。此对象包含创建或查找目录的 getDirectory 方法。
In order to create a directory you have to use the DirectoryEntry
object. This object contains the getDirectory method which creates or looks up a directory.
支持的平台:
- Android
- BlackBerry WebWorks(OS 5.0及更高版本)
- iOS
- Windows Phone 7和8
- Windows 8
- Android
- BlackBerry WebWorks (OS 5.0 and higher)
- iOS
- Windows Phone 7 and 8
- Windows 8
示例:
<!DOCTYPE html>
<html>
<head>
<title>Local File System Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);
}
function onFileSystemSuccess(fileSystem) {
console.log(fileSystem.name);
var directoryEntry = fileSystem.root;
directoryEntry.getDirectory("newDir", {create: true, exclusive: false}, onDirectorySuccess, onDirectoryFail)
}
function onDirectorySuccess(parent) {
console.log(parent);
}
function onDirectoryFail(error) {
alert("Unable to create new directory: " + error.code);
}
function onFileSystemFail(evt) {
console.log(evt.target.error.code);
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Local File System</p>
</body>
</html>
我希望这有助于。
这篇关于如何创建目录中的文件夹在iphone和android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!