Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

New Developer
Posts: 14
Registered: ‎11-20-2013
My Device: Blackberry Z10

Problem recursively creating directory paths outside sandbox on blackberry10 using cordova2.9 and webworks

[ Edited ]



Can somebody explain to me what's going on here? The code below works perfectly well on Android but does not work on blackberry 10.


For the first two directory structures in the array, I do not see parentDir.getDirectory() being called, however the last path in the array ("dir/3/dir6") is created successfully in the "parentFolder" folder in blackberry.io.home folder.


var dirList;
    // Wait for device API libraries to load
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    function onDeviceReady() {
		alert("device ready");
		blackberry.io.sandbox = false;
		dirList = ["dir1/dir4/", "dir2/dir5/", "dir3/dir6/"];
	function getFileSystem(){
    			LocalFileSystem.PERSISTENT, 0,
    			function onFileSystemSuccess(fileSystem)
    				console.log("Success getting filesystem !!!");
    				console.log("Failed to get the filesystem !!!!!");
    function createDirectoryRecursive(fs){
    	var i;
    	for(i = 0; i < dirList.length; i++){
    		createDirs(fs.root, dirList[i], -1);
    function createDirs(parentDir, filePath, index)
    	console.log("createDirs params ===> parentDir=" + parentDir.toURL() + " filePath=" + filePath + " index=" + index); 
    	var arrDirs = filePath.split("/");
	console.log("number of levels in path = " + arrDirs.length);
    	if (index >= (arrDirs.length - 1))
    		console.log("Done with " + filePath);
    		var dirName = "parentFolder";
    		if (index >= 0)
    			dirName = arrDirs[index];
    			console.log("current dirName is " + dirName);
    		//if device is Blackberry, build up a full directory path as we are trying to install outside of sandbox
		var path, dirToCreate = ""
    		if(device.platform == "blackberry10"){
    			path = "parentFolder/";
    			console.log("Paths ======> arrDirs = " + arrDirs + " index = " +index);
    			for (i = 0; i <= index; i++){
    				path += arrDirs[i] + "/";
    				console.log("path = " + path + " i = " + i + " index = " +  index);
    			dirToCreate = blackberry.io.home + "/" + path;
    			dirToCreate = dirToCreate.substring(0, dirToCreate.length - 1);
    			console.log("Paths Trying to create " + dirToCreate);
    			dirName = dirToCreate;
    		parentDir.getDirectory(dirName, {create: true, exclusive: false},
    							   function (directoryEntry) {
    										console.log("getDirectory callback =======> created directory " + directoryEntry.fullPath);
    										console.log("getDirectory callback =======> Current arrdirs " + arrDirs);
    										createDirs(directoryEntry, filePath, index + 1);
    								   function (error) {console.log("Failed to get directory " + dirName + " Error code : " + error.code);});


The code actually does enter cordova's DirectoryEntry.getDirectory function for all the directories in the array, however no callbacks (success or failure) are called. Only the last directory path in the list is processed and created successfully on the device.




Posts: 1,230
Registered: ‎03-20-2011
My Device: Playbook, Z10 LE, Dev Alpha B, 2x Dev Alpha C
My Carrier: 3, Orange, Vodafone

Re: Problem recursively creating directory paths outside sandbox on blackberry10 using cordova2.9 and webworks

This is an issue with any language


You need to de-construct the path then go as far as you can without a fail and build on top


For example if you have /a/b/c and want /a/b/c/d/e/f you get as far as c then a fail so you have to construct d, e and f


This is not a fault with amy specific language - its the way the OS works (any OS)


Certain languages cater for being sloppy but - do you wanna be a sloopy coder?



Click the like button if you find my posts useful!