最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - node.js create hidden directory (Windows) - Stack Overflow

programmeradmin3浏览0评论

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
Add a comment  | 

3 Answers 3

Reset to default 8

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

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.

发布评论

评论列表(0)

  1. 暂无评论