How to create a folder/file browser

Hi, i have some code but my problem is that ‘entries’ is undefined in the success function and i don’t know why :frowning:

ionViewDidLoad() {
    console.log('ionViewDidLoad ModalConfFolderPage');
    console.log(this.file.externalRootDirectory);
    let path: string = this.file.externalRootDirectory;
    this.listPath(path);
}

listPath(path: string){
  	this.file.resolveDirectoryUrl(path).then((dirEntry) => {
  			var directoryReader = dirEntry.createReader();
        	directoryReader.readEntries(onSuccessCallback,onFailCallback);
  		}, (errRoot: any) => {
  			console.log('ERROR resolveDirectoryUrl');
  		});

//----------------PROBLEMS HERE!!--------------------------
  		function onSuccessCallback(entries){
  			console.log('SUCCESS');
  			console.log(entries.lenght);
  			console.log(entries[0]);
	    	for(var i=0; i<entries.lenght; i++){
	    		let row:any = entries[i];
	    		let cad:string = row.nativeURL+row.name;
	    		if(row.isDirectory){
	    			this.folders.push(cad);
	    			console.log(this.folders[i]);
	    		}
	    	}
	    }

	    function onFailCallback(e) {
	    	console.log(e);
	    }
  }

In my view i can’t see folder list because ‘entries’ is undefined and so for loop is skipped. Any sugest?

Where does this come from? What is this?

from constructor, i’m using file plugin native and this is its import right?:
import { File } from '@Ionic-native/file';

constructor:

constructor( public file: File) {  	  
}

//and then the rest of code

Never type the word “function” inside of one. Always use a lambda or arrow function. I’m 80% sure you are losing execution context.

of curse, i’m gonna test your suggest and i’ll come back with my results :slight_smile: