是否有一种跨操作系统的方式来使用 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/