Getting the full path of a DirectoryEntry

爷,独闯天下 提交于 2019-12-11 20:12:06

问题


Does anyone know how to get the full path of a DirectoryEntry object in a Chrome Packaged App, without any tildes or other shortcuts?

I am writing a Google Chrome Packaged App. My app has a button where a user can choose a directory using chrome.fileSystem API. When the directory choice comes back to my app, it is represented by a DirectoryEntry object, which is defined in the File API. The object looks like this in the console:

DirectoryEntry {
  filesystem: DOMFileSystem
  fullPath: "/to_read"
  isDirectory: true
  isFile: false
  name: "to_read"
  __proto__: DirectoryEntry
}

I am using Windows and the full path of the directory is

C:\Users\David\Desktop\to_read

I would like a function that can return that path or something close. Unfortunately, the closest thing I found is chrome.fileSystem.getDisplayPath, but that returns the following:

~\Desktop\to_read

The return value from getDisplayPath is not useful to me, because I want to get the full name of the directory (including the drive) so I can compare it to some other full directory paths I have.

I tried calling toURL() on the DirectoryEntry and it returned an empty string.

A bit about my project: I want to write an iTunes library synchronizer as a Chrome Packaged App. The iTunes library XML file contains full paths like file://localhost/D:/David/Music/Bob/Bob%20Album/01%20Bob.mp3. The user will give my app access to his music folders, and I want to be able to tell if he gave me access to the right folders.


回答1:


The only full paths available are those returned by getDisplayPath.

The mediaGalleries API may be a better fit for your project: http://developer.chrome.com/apps/mediaGalleries.html#iTunes.




回答2:


If you have a full path path/to/the/file.mp3 and you want to load the file directly with tis you can do it but the solution is not perfect. Use the chrome.mediaGalleries API to ask where the user saves his music (in your case), then you can write a loop who check if one of the path repository is equal to a gallery.

For example if you got a file path/to/the/file.mp3 from the xml file and your galleries list looks like ["D", "to", "Videos"], write a function to check if each component of the file's path is a gallery. In this case your code will find "to", so you can launch a second function who use "the/file.mp3".

The second function has to use the given path and find if the gallery contains the right folders and finally the right file (use this example by Google). In the case you're trying to find "the/file.mp3" with the gallery to your loop has to find a directory named "the" then "file.mp3" (write a recursive function), if you find the file open it, otherwise come back to the first function if you haven't check all the galleries or all the path's component.




回答3:


This is currently (2014-01-10) not a feature of Chrome, but I have suggested it and they are working on it:

https://code.google.com/p/chromium/issues/detail?id=322952



来源:https://stackoverflow.com/questions/19883803/getting-the-full-path-of-a-directoryentry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!