使用Firefox Addon SDK列出所有驱动器 [英] List all drives using Firefox Addon SDK
问题描述
我发现这个代码为Windows,但我找不到一个跨操作系统的解决方案:
$ p $元c $ c元件.utils.import(资源: //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/zh-CN/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);
解析命令行工具的输出(如 df )在macos和linux。
从问题的评论中收集。
Is there a cross-OS way to list the paths of all mounted drives (harddisks, usb-drives, etc.) using the firefox addon sdk?
I found this code for Windows but i couldn't find a cross-OS solution:
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);
}
Source: https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Enumerating_drives_on_Windows
解决方案 So the Answer seems to be that there is no direct way but it is possible to use the sdk api to get the drives in 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);
}
and parse the output of commandline tools (like df
) in macos and linux.
Gathered from the comments of the question.
这篇关于使用Firefox Addon SDK列出所有驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!