javascript - 使用 Firefox Addon SDK 列出所有驱动器

标签 javascript firefox firefox-addon firefox-addon-sdk

是否有一种跨操作系统的方式来使用 firefox 插件 sdk 列出所有已安装驱动器(硬盘、USB 驱动器等)的路径?

我找到了这段适用于 Windows 的代码,但找不到跨操作系统的解决方案:

Components.utils.import("resource://gre/modules/FileUtils.jsm");

var root = new FileUtils.File("\\\\.");
var drivesEnum = root.directoryEntries, drives = [];
while (drivesEnum.hasMoreElements()) {
  drives.push(drivesEnum.getNext().
    QueryInterface(Components.interfaces.nsILocalFile).path);
}

来源:https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Enumerating_drives_on_Windows

最佳答案

所以答案似乎是没有直接的方法,但可以使用 sdk api 在 windows 中获取驱动器:

Components.utils.import("resource://gre/modules/FileUtils.jsm");

var root = new FileUtils.File("\\\\.");
var drivesEnum = root.directoryEntries, drives = [];
while (drivesEnum.hasMoreElements()) {
  drives.push(drivesEnum.getNext().
    QueryInterface(Components.interfaces.nsILocalFile).path);
}

并在 macos 和 linux 中解析命令行工具(如 df)的输出。

从问题的评论中收集。

关于javascript - 使用 Firefox Addon SDK 列出所有驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26973645/

相关文章:

javascript - 在进行需要身份验证的 ajax 调用时如何抑制浏览器的 "authentication required"对话框?

javascript - 动态填充复选框并在 React Redux 中维护复选框的状态

javascript - 如何使用 javascript 限制输入值?

firefox - Firefox中的HTTP header "q"因素?

json - 解析 mozilla firefox json 文件的快速而肮脏的方法

javascript - 使用 Firefox 附加组件 SDK 打开后台窗口

javascript - Firebase 与 Microsoft 的身份验证给出了空用户对象

javascript - 在 componentDidMount 中卸载什么

html - 如何从链接在特定浏览器中打开特定 URL?

javascript - Firefox browser.tabs.query({}).then() 未定义