List all drives using Firefox Addon SDK

2019-05-17 23:40发布

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条回答
我只想做你的唯一
2楼-- · 2019-05-18 00:14

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.

查看更多
登录 后发表回答