问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/26973645/list-all-drives-using-firefox-addon-sdk