我想做的事:
我想创建一个用于测试目的的 Chrome 扩展程序。该扩展名应该可以 访问本地 上的目录和文件硬盘 .
我是如何做到的:
我请求了 file:///*
的权限在我的 manifest.json
文件。然后我确保复选框 Allow access to file URLs
被检查。然后我为一个文件制作了一个 XHR:
var xhr = new XMLHttpRequest();
xhr.open("GET", 'file://c:/dir/file.name', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();
...以及整个目录的 XHR:
var xhr = new XMLHttpRequest();
xhr.open("GET", 'file://c:/dir/', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();
...对于整个文件系统:
var xhr = new XMLHttpRequest();
xhr.open("GET", 'file:///', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();
发生了什么:
默认的人类可读目录概述:
.
<html>
<head>
<script>
[...]
</script>
<style>
[...]
</style>
<title id="title"></title>
</head>
<body>
<div id="listingParsingErrorBox" i18n-values=".innerHTML:listingParsingErrorBoxText"></div>
<span id="parentDirText" style="display:none" i18n-content="parentDirText"></span>
<h1 id="header" i18n-content="header"></h1>
<table id="table">
<tr class="header">
<td i18n-content="headerName"></td>
<td class="detailsColumn" i18n-content="headerSize"></td>
<td class="detailsColumn" i18n-content="headerDateModified"></td>
</tr>
</table>
</body>
</html>
[...]
<script>start("C:\\dir\\");</script>
<script>addRow("..","..",1,"0 B","11/11/11 11:11:11 AM");</script>
<script>addRow("file.name","file.name",0,"4.9 kB","11/11/11 11:11:11 PM");</script>
我的问题:
我能够阅读简单的文件。但是我的分机怎么能得到一个不错的 目录的机器可读概述 还是整个文件系统?谢谢。
编辑:我知道 FileSystem API 旨在访问沙盒
filesystem://
,但也许 Chrome 允许扩展程序也访问 file://
.我找不到任何关于 file://
的文档从 Chrome 扩展程序访问,所以我只能猜测。
最佳答案
关于google-chrome - Chrome 扩展程序 : How to List The Contents of Local Directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11452758/