列出 nodejs 中的分区 [英] list partitions in nodejs

查看:31
本文介绍了列出 nodejs 中的分区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 nodejs 获取 Windows 中的分区列表.fs.readdir 适用于 C: 以下或包括 C: 的任何文件夹,但我不知道要给它什么才能拥有C:"、D:"等分区列表.

I would like to get the list of partitions in windows, using nodejs. fs.readdir works fine for any folder below or including C:, but I cant figure out what to give it to have the list of partitions like "C:", "D:" and so on.

有人知道我应该用什么吗?

Anyone know what I should use?

推荐答案

node.js 中没有 api 来列出分区.一种解决方法是使用 child_process 并执行 wmic 命令(或任何可以列出分区的命令).

There is no api in node.js to list partitions. One workaround is to use child_process and execute wmic command (or any command which can list partitions).

var spawn = require('child_process').spawn,
    list  = spawn('cmd');

list.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});

list.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

list.on('exit', function (code) {
  console.log('child process exited with code ' + code);
});

list.stdin.write('wmic logicaldisk get name\n');
list.stdin.end();

这篇关于列出 nodejs 中的分区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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