0

This is my code, I'm trying to return entries as a return-value for listDir to get it from outside, but it's not working.

function listDir(path){
    var files;
    window.resolveLocalFileSystemURL(path,
      function (fileSystem) {
        let _this = this;
        var reader = fileSystem.createReader();
        reader.readEntries( (entries) => {
            _this.files = entries;
        },
          (err)=>(console.log(err))
        );
      },(err)=>(console.log(err))
    );
    return files;
}

What is wrong I can not return value of entries It always undefined.

XSC
  • 1
  • 3
  • try setting a timeout its returning files is before it initialized. Comment if you need help with it. – seriously Jun 10 '21 at 23:49
  • A timeout is the absolute worst way to deal with this. You now then have a race condition that will work *sometimes* meaning its even harder to trace. This is an async problem and needs any one of the solutions from the linked duplicate. – zero298 Jun 11 '21 at 00:24
  • I think you are all right but the solution in first and third comments, But I don't know how to make it right I tried a lot and it's not working – XSC Jun 11 '21 at 05:31
  • I finally did it thanks a lot :D – XSC Jun 11 '21 at 05:39

0 Answers0