3

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

Nick Russler
  • 4,608
  • 6
  • 51
  • 88
  • I think only windows has "drives" other OS just have root directories. – Noitidart Nov 17 '14 at 15:54
  • You could probably fake it by listing /Volumes on OS X and maybe shelling out to `df` on UNIX and parsing the results. The last option on Linux machines might vary a lot in terms of exact output. – therealjeffg Nov 18 '14 at 00:28
  • @canuckistani The option for OS X sounds fine, is there no command line tool available which output is machine readable / normalized across distros? – Nick Russler Nov 18 '14 at 11:09
  • That would be the `df` [utility](http://unixhelp.ed.ac.uk/CGI/man-cgi?df) – therealjeffg Nov 18 '14 at 17:26

1 Answers1

2

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.

Nick Russler
  • 4,608
  • 6
  • 51
  • 88