Welcome!

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

Reply
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Read private files with HTML5 DirectoryEntry then FileEntry

Eric, thank you. I will try your code and let you know if it works.

Twitter : @LaurentKP
My apps
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Read private files with HTML5 DirectoryEntry then FileEntry

Sorry but I'm not a javascript expert and I'm not used to callback functions.

Could I just return entries there and consider showEm returns an array of directory entries ?

 

function showEm() {
    showLocalFileSystem(function (entries) {
        //Do whatever I was interested in doing when this funciton returns
        //Modify, etc etc
return entries; console.log(entries); });
}
Twitter : @LaurentKP
My apps
Please use plain text.
BlackBerry Development Advisor (Retired)
erikjohnzon
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Read private files with HTML5 DirectoryEntry then FileEntry

Nope showEm has already been executed, but while it was executing it put your callback on the stack to be popped off when the showLocalFileSystem calls the callback. This is a non-blocking way of executing your code since JS is single threaded. The browser will go off do other things then your code will be run later.

 

You are wrapping any of your code in a function, so that you only execute it when the directories have been properly read. the nice thing about a callback is that your code will be executed sequentially the minute that the callbcak is called from the showLocalFileSystem(callback) function.

 

I put comments where you want to put all your code, inside there you can call another sequential function or do anything you like. This is just a natural trick in JS to perform something in an asynchronous nature. You can't really return entries, since the showEm

 

function showEm() {
    showLocalFileSystem(function (entries) {
        //Do whatever I was interested in doing when this funciton returns
        //Modify, etc etc
//showEm has already returned!
// Any code you want executed AFTER the showLocalFileSystem function should go here and below
// and will have access to the entries passed back through the anonymous callback this way
// it can then execute sequentially in a non-blocking way console.log(entries); });
}
@erikjohnzon
erjohnson@blackberry.com
Please use plain text.
Contributor
fmbois
Posts: 16
Registered: ‎08-27-2011
My Device: Curve9300, PlayBook
My Carrier: SFR

Re: Read private files with HTML5 DirectoryEntry then FileEntry

Thanks erikjohnzon. It works for me. In fact all what I needed is the path:

blackberry.io.home + '/../app/native/'

There is no way for me to know the '../app/native' stuff otherwise than from you.

 

Please use plain text.
BlackBerry Development Advisor (Retired)
erikjohnzon
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Read private files with HTML5 DirectoryEntry then FileEntry

Awesome! I'll code up a simple wrapper to help make that easier next time :smileyhappy:.
@erikjohnzon
erjohnson@blackberry.com
Please use plain text.