Read Folder Contents in Chrome Application

2019-09-03 16:05发布

问题:

I have an application which outputs text files periodically with data in it. The text files are initiated from within the application and a datetime/context sensitive name -- though always output to the same folder. I would like to write a chrome application that can watch the folder these files are output to, read them, parse them, and then display them in a friendly manner.

However, there does not seem to be any obvious way to get the contents of a folder in a chrome app. I've read suggestions to use an NPAPI plugin, but it appears those are being phased out. NACL seems like it might do it but I've also read that it doesn't have full access to the file-system.

Is this something that can even be done? Reading the contents of an arbitrary folder from a packaged chrome application?

回答1:

Read the docs: chrome.fileSystem

Chrome Apps can access a directory (after getting the user to select it once) and periodically poll it. Unfortunately, there seems to be no event-based approach to watch a folder for changes.

You should check out the HTML5Rocks tutorial on HTML5 Filesystems. Ignore the abandoned standard warning: yes, it's only supported in Chrome, but Chrome APIs rely on it and it's not going away.