其他分享
首页 > 其他分享> > electron 描扫磁盘盘符,获取U盘盘符

electron 描扫磁盘盘符,获取U盘盘符

作者:互联网

用这个库 https://github.com/cristiammercado/node-disk-info

// 直接抄的DEMO
const nodeDiskInfo = require('./dist/index');

// async way
nodeDiskInfo.getDiskInfo()
    .then(disks => {
        printResults('ASYNC WAY', disks);
    })
    .catch(reason => {
        console.error(reason);
    });

// sync way
try {
    const disks = nodeDiskInfo.getDiskInfoSync();
    printResults('SYNC WAY', disks);
} catch (e) {
    console.error(e);
}

function printResults(title, disks) {

    console.log(`============ ${title} ==============\n`);

    for (const disk of disks) {
        console.log('Filesystem:', disk.filesystem);
        console.log('Blocks:', disk.blocks);
        console.log('Used:', disk.used);
        console.log('Available:', disk.available);
        console.log('Capacity:', disk.capacity);
        console.log('Mounted:', disk.mounted, '\n');
    }

}


标签:描扫,log,const,disks,盘符,printResults,console,disk,U盘
来源: https://www.cnblogs.com/ybixian/p/15080251.html