获取节点js的文件系统types

我正在一个节点js项目工作,我需要得到一个磁盘的文件系统types,即我想知道,如果它是FAT或NTFS等…有什么办法,我可以用节点js完成这个? 任何帮助表示赞赏。 谢谢。

因为您没有指定目标机器的操作系统,所以您可以在Windows下使用这样的命令:

fsutil fsinfo volumeinfo <disk letter here>: 

显示输出类似于这个:

 H:\>fsutil fsinfo volumeinfo c: Volume Name : Volume Serial Number : 0x4c31bcb3 Max Component Length : 255 File System Name : NTFS Supports Case-sensitive filenames Preserves Case of filenames Supports Unicode in filenames Preserves & Enforces ACL's Supports file-based Compression Supports Disk Quotas Supports Sparse files Supports Reparse Points Supports Object Identifiers Supports Encrypted File System Supports Named Streams 

您只需要正确parsing命令输出。 我build议你将数组中的文件系统名称存储起来,然后寻找除第一行以外的所有命令输出。 这样你可以确定目标机器使用哪个文件系统。

在这里你有代码打印这个命令输出到你的命令行:

 const { exec } = require('child_process'); exec('fsutil fsinfo volumeinfo c:', (err, stdout, stderr) => { if (err) { // node couldn't execute the command return; } // the *entire* stdout and stderr (buffered) console.log(`stdout: ${stdout}`); }); 

这是未经testing的代码,我真的认为你想写自己的片段。 我不能决定这个代码是否工作,因为我现在没有机会。

另外,你为什么要检查使用的文件系统?

你可以使用github.com/resin-io-modules/drivelist

然后

 const drivelist = require('drivelist'); drivelist.list((error, drives) => { if (error) { throw error; } console.log(drives); });