List all drives using Firefox Addon SDK

吃可爱长大的小学妹 提交于 2019-12-22 11:16:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!