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());
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());
Share
Improve this question
asked Feb 26, 2014 at 21:10
Stefan ProfanterStefan Profanter
6,8367 gold badges44 silver badges75 bronze badges
2
- not sure this is possible at the moment – RobertPitt Commented Feb 26, 2014 at 21:13
- Is there a platform independent way to do this? – Dom Vinyard Commented Jul 4, 2016 at 8:26
3 Answers
Reset to default 8There 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().
I've used library hidefile, to Hide files and directories on all the platforms.
const hidefile = require('hidefile');
hidefile.hideSync('.hiddenDir');
No extra code to write for diff platforms. I've used this on my Electron JS Desktop App. Which works properly for all the platforms.