如何使用Cordova创建子文件夹 [英] How to create subfolder using Cordova
本文介绍了如何使用Cordova创建子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Cordova,并且尝试在设备上的SD卡的根目录中创建一个文件夹。我使用以下代码创建了文件夹,并在其中添加了文件'login.txt':
I'm using Cordova and I tried to create a folder to the root of my SD card on a device. I used the following code for create the folder and add a file 'login.txt' inside it:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
function gotFS(fileSystem) {
fileSystem.root.getDirectory("citylook", {create: true}, gotDir);
}
function gotDir(dirEntry) {
dirEntry.getFile("login.txt", {create: true, exclusive: true}, gotFile);
}
function gotFile(fileEntry) {
// Do something with fileEntry here
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwriteend = function(evt) {
console.log("contents of file now 'some sample text'");
writer.truncate(11);
writer.onwriteend = function(evt) {
writer.seek(0);
writer.write(testo);
writer.onwriteend = function(evt){
console.log("contents of file now '"+testo+"'");
}
};
};
writer.write("some sample text");
}
function fail(error) {
console.log(error.code);
}
现在,我需要在 citylook文件夹中创建一个文件夹,所以我尝试过此操作:
Now, I need to create a folder inside "citylook" folder, so I tried this:
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null);
}
function onSuccess() {
fileSystem.root.getDirectory("citylook", {create: true, exclusive: false}, onGetDirectoryWin, onGetDirectoryFail);
fileSystem.root.getDirectory("citylook/nuovo", {create: true, exclusive: false}, onGetDirectoryWin2, onGetDirectoryFail2);
}
但我无法创建子文件夹。我的代码有什么问题?谢谢。
but I can't create a subfolder. What's is wrong in my code? Thank you.
fileSystem.root.getDirectory("citylook", {create: true}, gotDir);
fileSystem.root.getDirectory("citylook/subfolder", {create: true}, gotDir);
推荐答案
window.resolveLocalFileSystemURL(
cordova.file.externalDataDirectory,
function(entry) {
entry.getDirectory(
"myNewDirectory",
{ create: true, exclusive: false },
function(result) {
alert(JSON.stringify(result));
},
onError
);
}
);
我正在使用cordova为Android /数据//文件成功创建一个文件夹。
i'm using cordova create a folder to the Android/data//files success.
这篇关于如何使用Cordova创建子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文