Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js create hidden directory (Windows)

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());
like image 960
Stefan Profanter Avatar asked Dec 05 '22 07:12

Stefan Profanter


2 Answers

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).

like image 62
Ethan Brown Avatar answered Dec 06 '22 21:12

Ethan Brown


You could try executing the DOS command attrib using child_process.spawn().

like image 35
Ian Stevens Avatar answered Dec 06 '22 20:12

Ian Stevens