How To Create Subfolder Using Cordova
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
Solution 1:
window.resolveLocalFileSystemURL(
cordova.file.externalDataDirectory,
function(entry) {
entry.getDirectory(
"myNewDirectory",
{ create: true, exclusive: false },
function(result) {
alert(JSON.stringify(result));
},
onError
);
}
);
i'm using cordova create a folder to the Android/data//files success.
Solution 2:
var type = window.PERSISTENT;
var size = 5*1024*1024;
window.requestFileSystem(type, 0, successCallback, errorCallback);
functionsuccessCallback(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);
}
functionerrorCallback(error) {
alert("ERROR: " + error.code)
}
This code helps to create folders and sub-folders in root. /Albums is the main folder. /Albums/Images/ and /Albums/Audio/ are the sub-folders(Images and Audio)
Post a Comment for "How To Create Subfolder Using Cordova"