How to get files from created directory in ionic? using get() method and show it on screen

444 views Asked by At

I want to display the files in created directory. The files may be any format like audio, video, image etc. This is How I able to create a directory and remove directory. Home.ts

 createDirectory(){

    this.file.createDir(this.file.externalRootDirectory, "DirectoryFile", false )
    .then((directoryEntry) =>{

      alert("directory created"+ directoryEntry.fullPath);
    }
  ).catch((error)=>{
    alert(JSON.stringify(error));
      })

  }

  removeDirectory(){
    this.file.removeDir(this.file.externalRootDirectory, "DirectoryFile")
    .then((resultData) =>{
      if(resultData.success){
        alert("directory removed" + resultData);
      }
    })
      .catch((err) =>{
      alert(JSON.stringify(err));
    })


enter code here
2

There are 2 answers

0
Rajan On

You can use listDir

listDir(path, dirName)
  List files and directory from a given path.
this.file.listDir('some/path/directory', '');
1
vinod kumar On

I tried like this but am getting [obj obj] on screen

    listAllFiles(){
    this.file.listDir(this.file.externalRootDirectory, "DirectoryFile")
    .then((entry) => {
      this.showFile=entry;
    })
    .catch((err) =>{
      alert(JSON.stringify(err));
    })
  }