繁体   English   中英

node.js创建隐藏目录(Windows)

[英]node.js create hidden directory (Windows)

如何在Windows下使用node.js创建隐藏目录

在Linux上我会使用:

var fs = require('fs');
fs.mkdirSync(".hiddenDir");

但在Windows上我需要另外设置目录的HIDDEN属性。

在Perl中我会使用:

Win32::File::SetAttributes(".hiddenDir", Win32::File::DIRECTORY() | Win32::File::HIDDEN());

您可以尝试使用child_process.spawn()执行DOS命令attrib

有一个库可以处理这个, fswin

https://www.npmjs.org/package/fswin

请在此处查看setAttribute的文档:

https://github.com/xxoo/node-fswin/wiki/setAttributes-and-setAttributesSync

换一种说法:

fswin.setAttributesSync('test.txt', { IS_HIDDEN: true });

请注意,这需要一个本机编译器(它在文档中列出了Visual Studio,但也许可以使用其他编译器)。

我用库hidefile隐藏在所有平台上的文件和目录

const hidefile = require('hidefile');

hidefile.hideSync('.hiddenDir');

没有额外的代码可以为diff平台编写。 我在Electron JS桌面应用程序上使用过它。 哪个适用于所有平台。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM