Chrome应用创建并写入文件 [英] Chrome app create and write to file

查看:305
本文介绍了Chrome应用创建并写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将chrome.apps用于需要写入多个数据日志文件的程序.然后,用户需要能够在其文件系统中的应用程序外部访问这些日志文件,以进行后期处理.

I am attempting to use chrome.apps for a program that needs to write multiple separate log files of data. The user then needs to be able to access these these log files outside of the app in their file system for post processing.

这将需要执行很多次,因此,生成文件所需的交互操作最少,甚至不需要用户交互.尽管在任何本机程序代码中这都很简单,但是我发现使用chrome应用程序很难做到这一点. 例如.我可以使用Chrome应用创建"log_file.txt"吗?没有用户交互的"log_file2.txt"? 有什么方法可以让用户正义指定一个目录,然后从我的应用中,我可以在该目录中创建多个文件而无需用户交互? 我尝试在代码中执行此操作,但是我需要chrome.filesystem的入口"句柄. "getEntry"方法需要一个"entry",因此似乎无法创建新的"entry"以使我可以写入新文件. 任何想法,将不胜感激!

This will need to be done many times so minimum to no user interaction would be desired for file generation. While this is simple in any native program code, I've been finding this very difficult to do with chrome apps. E.g. can I use chrome apps to create "log_file.txt" & "log_file2.txt" without user interaction? Is there any way I can have the user just specify a directory then from my app, I would be able to create multiple files within that directory without user interaction? I've tried to do this in code but I need "entry" handles for the chrome.filesystem. The "getEntry" method requires an "entry" so it seems impossible to create new "entry"s such that I can write to new files. Any ideas would be appreciated!

推荐答案

有什么方法可以让用户只指定一个目录,然后从我的应用程序中创建,而无需用户干预,我就能在该目录中创建多个文件吗?

Is there any way I can have the user just specify a directory then from my app, I would be able to create multiple files within that directory without user interaction?

是的.您需要使用以下目录请求

Yes. You need to request a directory with

chrome.fileSystem.chooseEntry({type: "openDirectory"}, /*...*/);

只要您有权限

{"fileSystem": ["write", "retainEntries", "directory"]} 

您将能够在该目录中创建文件,并保留"(保存)目录条目以供以后重用,而无需再次询问用户.拥有DirectoryEntry后创建文件应类似于.

you will be able to create files in that directory, and "retain" (save) the directory entry for later reuse without asking the user again. Creating the files once you have a DirectoryEntry should be similar to this.

但是需要最少的交互(最初要求文件夹).

But that minimum of interaction (asking for the folder initially) is required.

这篇关于Chrome应用创建并写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆