I'm working on a project in node js and I need to get the file system type of a disk i.e., I want to know if it's FAT or NTFS etc... Is there any way I can accomplish this with node js? Any help is appreciated . Thanks.
fs it's a native node. js module, you don't need install it.
Node. js includes fs module to access physical file system. The fs module is responsible for all the asynchronous or synchronous file I/O operations.
With Node. js, you can programmatically manipulate files with the built-in fs module. The name is short for “file system,” and the module contains all the functions you need to read, write, and delete files on the local machine.
The Node.js file system module allows you to work with the file system on your computer. To include the File System module, use the require() method: var fs = require('fs');
As you didn't specify target machine's operating system, you can use such command under Windows:
fsutil fsinfo volumeinfo <disk letter here>:
to show output simillar to this one:
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
You need only to parse command output correctly. I would recommend you storing filesystem names in array and seeking for every in command output excluding first line. This way you can be sure which filesystem is used by target machine.
Here you have code to print what does this command output to your commandline:
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}`);
});
This is untested code, I really think that you want to write own snippet. I can't decide will this code work because I have no opportunity now.
Also, why would you check filesystem used?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With