How can I create a hidden directory using node.js under Windows?
On Linux I would use:
var fs = require('fs');
fs.mkdirSync(".hiddenDir");
but on Windows I need to additionally set the HIDDEN attribute of the directory.
In Perl I would use:
Win32::File::SetAttributes(".hiddenDir", Win32::File::DIRECTORY() | Win32::File::HIDDEN());
There is a library available to handle this, fswin
:
https://www.npmjs.org/package/fswin
See the documentation for setAttribute
here:
https://github.com/xxoo/node-fswin/wiki/setAttributes-and-setAttributesSync
In other words:
fswin.setAttributesSync('test.txt', { IS_HIDDEN: true });
Note that this requires a native compiler (it lists Visual Studio in the documentation, but perhaps others could be used).
You could try executing the DOS command attrib using child_process.spawn().
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