Cordoba, an Android application, how to create a subfolder

I am using cordova and I am trying to create a folder in the root of my SD card on the device. I use the following code to create a folder and add the login.txt file to 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); } 

Now I need to create a folder inside the "citylook" folder, I will try:

 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 wrong with my code?

Thankyou

SOLVE:

 fileSystem.root.getDirectory("citylook", {create: true}, gotDir); fileSystem.root.getDirectory("citylook/subfolder", {create: true}, gotDir); 
+1
source share
1 answer
 var type = window.PERSISTENT; var size = 5*1024*1024; window.requestFileSystem(type, 0, successCallback, errorCallback); function successCallback(fs) { var dir=fs.root; alert('root -'+dir.fullPath);// O/P:-root -/ dir.getDirectory('Albums', {create: true}, function(dirEntry) { alert('Albums Path:'+dirEntry.fullPath);// O/P:-Allbums Path: /Albums/ dirEntry.getDirectory('Images',{create:true},function(subDir){ alert('Hello'); alert('SubDirPath='+subDir.fullPath);//output:-SubDirPath=/Albums/Images/ //subDir.getFile('Log.txt',{create: true, exclusive: false}, function(fileEntry) { //writeFile(fileEntry, null, isAppend); //alert('File Path'+fileEntry.fullPath); }, onErrorCallback); },errorCallback); dirEntry.getDirectory('Audio',{create:true},function(subDir){ alert('Hello'); alert('SubDirPath='+subDir.fullPath);//output:-SubDirPath=/Albums/Audio/ },errorCallback); }, errorCallback); } function errorCallback(error) { alert("ERROR: " + error.code) } 

This code helps to create folders and subfolders in the root. / Albums is the main folder. / Albums / Images / and / Albums / Audio / are subfolders (Images and Audio)

0
source

Source: https://habr.com/ru/post/1241697/


All Articles