systeminformation
systeminformation copied to clipboard
fsSize() option to return only a specific drive on Windows
I suppose this is related to #314 and #299 in some ways. I have read them and feel like my request might not be doable, but here goes nothing :
Would it be possible to only get one drive's size instead of all the drives, in case a network drive is disconnected somehow? My main issue is that I check for available disk space on a specific drive before downloading something, and the fsSize() promise never resolves or resolves incorrectly due to the network drive being unreachable even though it's totally unrelated to where I want to check available disk space.
Given what I've read in the aforementionned issues, I'd understand if it wasn't possible given Windows' limitations :)
Thanks in advance for your reply.
@AxelTerizaki if you change filesystem.js a bit you can get it to work!
first you'll need to be able to pass a drive name into the function so on ln 39 change it to
function fsSize(callback, drive) {
then we'll want to pass that to the powershell command it runs on windows so ln 129 make a const with the optionally filtered command, something like
const cmd = `Get-WmiObject Win32_logicaldisk | select Caption,FileSystem,FreeSpace,Size ${drive ? `| where -property Caption -eq ` + drive : ''} | fl`;
then just pass that in as the string instead on ln 131 and you should be good!
si.fsSize()
.then(data => console.log(data))
.catch(error => console.error(error));
[
{
fs: 'C:',
type: 'NTFS',
size: 510980517888,
used: 493503086592,
available: 17477431296,
use: 96.58,
mount: 'C:'
},
{
fs: 'D:',
type: 'NTFS',
size: 1000200990720,
used: 810458435584,
available: 189742555136,
use: 81.03,
mount: 'D:'
},
{
fs: 'F:',
type: 'NTFS',
size: 1000196796416,
used: 724427710464,
available: 275769085952,
use: 72.43,
mount: 'F:'
}
]
will still give you all the drives
but
si.fsSize(null, 'C:')
.then(data => console.log(data))
.catch(error => console.error(error));
[
{
fs: 'C:',
type: 'NTFS',
size: 510980517888,
used: 493501169664,
available: 17479348224,
use: 96.58,
mount: 'C:'
}
]
should filter it to the specified drive!
if this is something the maintainer would like to add, I don't mind making a PR!
That's pretty good news, and I'd love for it to be implemented in the module by the author :)