Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list partitions in nodejs

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?

like image 829
user1703467 Avatar asked Sep 27 '12 13:09

user1703467


2 Answers

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();
like image 175
vinayr Avatar answered Oct 05 '22 05:10

vinayr


Not sure if it matches exactly what you're looking for, but we build a NodeJS module called drivelist that will return an array of connected drives with their respective mount points (e.g: mount letters in Windows):

[
    {
        device: '\\\\.\\PHYSICALDRIVE0',
        description: 'WDC WD10JPVX-75JC3T0',
        size: '1000 GB'
        mountpoint: 'C:',
        system: true
    },
    {
        device: '\\\\.\\PHYSICALDRIVE1',
        description: 'Generic STORAGE DEVICE USB Device',
        size: '15 GB'
        mountpoint: 'D:',
        system: false
    }
]

Non-removable drives are marked as system: false, you can filter by that property if that's what you're looking for.

The major advantage of this module is that is works in all major operating systems.

See https://github.com/resin-io-modules/drivelist

like image 37
jviotti Avatar answered Oct 05 '22 04:10

jviotti