Ionic Native File listDir function not working


#1

I can’t get the listDir method working on the Ionic Native File plugin. The function doesn’t seem to run at all and if I search the plugins/cordova-plugin-file directory for listDir, it returns no results… Has the function been removed? It is still listed in the Ionic documentation.

If this function has been removed, what solution do you recommend?

I’m using heaps of other File functions and they work fine.

my code below:

listDir(directory: string) {
return new Promise(function(resolve, reject){
this.file.listDir(this.file.applicationDirectory, ‘’).then(
(listing) => {
console.log(‘Directory listing below’);
console.log(listing);
resolve(listing);
}
).catch(
(err) => {
console.log(‘error listing directory’);
console.log(err);
reject(err);
}
)
})

}

Note: no logging fires on both success and error.

@ionic-native/core”: “4.3.2”,
"@ionic-native/file": “4.4.2”,
“cordova-plugin-file”: “4.3.3”,

thanks in advance


#2

First, I’m not sure why you’re wrapping a promise in a promise.

Secondly, I’d imagine your issue is the usage of function. That’s a word you pretty much never want to utilize in an ionic app. Instead you always want to utilize the fat arrows you’re using in other places.

So I’d do something like this:

listDir(directory: string) {
  return this.file.listDir(this.file.applicationDirectory, ‘’).then((listing) => {
    console.log(‘Directory listing below’);
    console.log(listing);
    return listing;
  });
}

(Apologies for any syntax errors, as I’m typing this up on my phone)


#3

Yes, it was the usage of the function. Thank you so much!