Ionic-native: File Plugin: How to obtain a DirectoryEntry/FileEntry of existing Directories/Files

Created on 7 Oct 2016  路  6Comments  路  Source: ionic-team/ionic-native

Hi,

is there an undocumented way to obtain a 'DirectoryEntry'/'FileEntry' of existing directories/files?

When creating Dirs/Files via createDir or createFile the promise returns a handy Entry type, but how to get it for already existing entries? Do I really have to use the low-level window.resolveLocalFilesystemUrl? getDirectory or getFile are present but _private_.

I think it is a good idea to provide such methods for the completeness of the API. Use-Case: check if a directory is present, if not create it and return a DirectoryEntry otherwise return the DirectoryEntry.

Most helpful comment

Do I really have to use the low-level window.resolveLocalFilesystemUrl

You will still have to do something like that. Ionic Native exports a wrapper for that function as well. You will need to do something like:

File.resolveDirectoryUrl('path/to/dir')
  .then((directoryEntry: DirectoryEntry) => {
    File.getFile(directoryEntry, 'myFile.txt', { create: false })
      .then((fileEntry: FileEntry) => {
        ....
      });
  });

All 6 comments

I have the same requirement. I'd like to check if a file already exists and return the FileEntry without modifying it.

Just pushed a commit (not merged yet) that makes resolveLocalFilesystemUrl and resolveDirectoryUrl methods public instead of private. They return a promise that resolves with Entry and DirectoryEntry respectively.

And I just made getFile and getDirectory public as well.

Do I really have to use the low-level window.resolveLocalFilesystemUrl

You will still have to do something like that. Ionic Native exports a wrapper for that function as well. You will need to do something like:

File.resolveDirectoryUrl('path/to/dir')
  .then((directoryEntry: DirectoryEntry) => {
    File.getFile(directoryEntry, 'myFile.txt', { create: false })
      .then((fileEntry: FileEntry) => {
        ....
      });
  });

Thank you very much, this will help a lot!

Is there a way to update https://github.com/driftyco/ionic-native-bower with the dist accordingly, it's a bit outdated. Installing ionic-native via npm I have the same problem as describe here: http://stackoverflow.com/questions/38683421/how-to-import-ionic-native-js-in-ionic-v1-angular-1-x

Was this page helpful?
0 / 5 - 0 ratings