01-22-2013 08:36 AM
This is the exact problem I had a while ago. I also opened a thread here http://supportforums.blackberry.com/t5/Web-and-Web![]()
If you found a solution please let us know.
I agree that the old directory api was better regarding this problem, RIM should fix this in a future version of webworks...
01-22-2013 09:04 AM
Yes perhaps the old API was more convenient, but I disagree it is not possible. In any event, if you feel the Cascades API provides an easier runtime by all means I encourage you to use it, it's a great product.
01-22-2013 09:07 AM
01-22-2013 09:22 AM
As I posted before here is what works for me, but it depens what it is you would like to list....
1. If you want to list the "sandbox" then you will only see files that your webview has created in the current session, or where created using the persistent tag from before, in this case you must have sandboxing set to false.
2. If you wish to list what is inside your .bar file then the following works for me on a BB10 device:
function showLocalFileSystem() {
// Get access to the root directory, your unix home is inside the local:///data/ directory of the bar so get out of there.
fs.root.getDirectory(blackberry.io.home + '/../app/native/', {create: false}, function(dirEntry) {
var dirReader = dirEntry.createReader();
var entries = [];
var readEntries = function() {
dirReader.readEntries (function(results) {
if (!results.length) {
//No more results then print them
console.log(entries);
} else {
keep appending as we move down the directory structure
entries = entries.concat(results);
readEntries();
}
}, errorHandler);
};
readEntries(); // Start reading dirs.
});
}
Let me know if you have problems with this LaurentC
01-22-2013 09:37 AM
Eric,
instead of loging the directory entries into the console, make your function return an array of the files or directories inside the given directory. It's not possible. the code below is not working :
function showLocalFileSystem() {
var d = new Array();
var iter = 0;
// Get access to the root directory, your unix home is inside the local:///data/ directory of the bar so get out of there.
fs.root.getDirectory(blackberry.io.home + '/../app/native/', {create: false}, function(dirEntry) {
var dirReader = dirEntry.createReader();
var entries = [];
var readEntries = function() {
dirReader.readEntries (function(results) {
if (!results.length) {
//No more results then print them
console.log(entries);
} else {
//keep appending as we move down the directory structure
entries = entries.concat(results);
d[iter]= results.name;
iter++;
readEntries(results);
}
}, errorHandler);
};
readEntries(); // Start reading dirs.
});
return d; //returns always an empty array
}
Maybe there is a solution, but I can't figure out how we could achieve this with BB10 webworks.
01-22-2013 09:45 AM
Thanks @erikjohnzon , it's exactly what I needed!
01-22-2013 09:49 AM
@andreyavram you only need to print the entries into the console ?
01-22-2013 09:51 AM
Of course this is an asynchronous function, if you wish to do that, then you would have to devise your own callback into the function. Just call the callback and pass the data when it is complete. I devised an example for you below to see how you can execute your code in a synchronous manner using an asynchronous function:
function showLocalFileSystem(callback) {
var entries = [];
fs.root.getDirectory(blackberry.io.home + '/../app/native/', {create: false}, function(dirEntry) {
var dirReader = dirEntry.createReader();
var readEntries = function() {
dirReader.readEntries (function(results) {
if (!results.length) {
callback(entries);
} else {
entries = entries.concat(results);
readEntries();
}
}, errorHandler);
};
readEntries(); // Start reading dirs.
});
}
function showEm() {
showLocalFileSystem(function (entries) {
//Do whatever I was interested in doing when this funciton returns
//Modify, etc etc
console.log(entries);
});
}
You need to do your work within showEm inside your callback.
01-22-2013 09:52 AM
If this works can we mark both the threads as solved please
.
01-22-2013 09:54 AM - edited 01-22-2013 09:54 AM
No, I don't need this right now...
I will probably use this at another app...I already built the app were I initially needed this (using a workaround, not involving parsing files like this)