Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Plugin: How to obtain a DirectoryEntry/FileEntry of existing Directories/Files #657

Closed
MaxDaten opened this issue Oct 7, 2016 · 6 comments

Comments

@MaxDaten
Copy link

MaxDaten commented Oct 7, 2016

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.

@ColinFrick
Copy link
Contributor

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

@ihadeed
Copy link
Collaborator

ihadeed commented Oct 12, 2016

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.

ihadeed added a commit that referenced this issue Oct 12, 2016
@ihadeed
Copy link
Collaborator

ihadeed commented Oct 12, 2016

And I just made getFile and getDirectory public as well.

@ihadeed
Copy link
Collaborator

ihadeed commented Oct 12, 2016

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) => {
        ....
      });
  });

@MaxDaten
Copy link
Author

Thank you very much, this will help a lot!

@MaxDaten
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants