我正在使用Node.js开发一个项目,需要获取磁盘的文件系统类型,比如FAT或NTFS等。是否有办法在Node.js中实现这一功能?非常感谢您的帮助。
我正在使用Node.js开发一个项目,需要获取磁盘的文件系统类型,比如FAT或NTFS等。是否有办法在Node.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
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}`);
});
这是未经测试的代码,我认为你可能想要编写自己的片段。我不能确定这段代码是否有效,因为目前没有机会进行测试。
此外,您为什么要检查使用的文件系统?
你可以使用github.com/resin-io-modules/drivelist
然后
const drivelist = require('drivelist');
drivelist.list((error, drives) => {
if (error) {
throw error;
}
console.log(drives);
});
stat
字段支持/有意义于不同的文件系统。在Windows中,对于NTFS,ctime
有意义,但是毫无用处。在Linux中,birthtime
仅受几个较新的文件系统支持。 - hippietrail