使用Firefox Addon SDK列出所有驱动器 [英] List all drives using Firefox Addon SDK

查看:113
本文介绍了使用Firefox Addon SDK列出所有驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一个跨操作系统的方式来列出所有安装的驱动器(硬盘驱动器,USB驱动器等)使用Firefox附加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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆