包括隐藏文件在内的所有内容的全局模式
我尝试获取一个包含每个子目录中的每个文件的全局模式,但我不知道如何包含隐藏文件。
例如,所有这些都应该匹配:
.git
.github/workflow.yml
index.js
src/index.js
src/components/index.js
这适用于具有名称和扩展名的所有文件,但忽略了隐藏文件:
**/**
更具体的背景:我想用除 node_modules
之外的所有文件(以及可能的其他文件)制作一个存档),使用 archiver 库。
archive.directory("???", {
ignore: ["node_modules/", ...some other files],
});
I try to get a glob pattern which includes every file in every subdirectory, but I can't figure out how to include hidden files.
Example, all those should match:
.git
.github/workflow.yml
index.js
src/index.js
src/components/index.js
This works for all files with name and extension, but leaves out hidden files:
**/**
More specific background: I want so make an archive with all files except node_modules
(and potentially some others), using the archiver library.
archive.directory("???", {
ignore: ["node_modules/", ...some other files],
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在使用归档库时遇到了同样的问题。我在文档中读到它用于 glob 模式 minmatch 库。该库为特定问题提供了一个选项。 这是文档中的位置。要获取所有文件、目录(递归)和隐藏文件(例如“.npmrc”),您需要使用“archive.glob”而不是“archive.directory”。
我的代码如下所示:
我传递了选项“dot: true”现在它还包含隐藏文件,
最终代码如下所示:
I was facing the same problem when using the archiver library. I read in the docs that it is using for the glob pattern the minmatch library. The library offering an option for the specific issue. Here is the location in the docs. To get all files, directories (recursive) and hidden files like ".npmrc" you need to use "archive.glob instead of "archive.directory".
My code looks like this:
I've passed the option "dot: true" and now it includes hidden files as well.
The final code would look like this:
最好的方法可能是使用两种单独的模式,其中一种匹配隐藏文件,另一种匹配非隐藏文件。
一种方法是
.* *
。但是,这也与目录本身.
和父..
匹配,这通常不是您想要的。避免此问题的模式是
.??* *
。假设您的目录中有以下文件。正如您在下面的示例中看到的,此 glob 模式匹配隐藏文件和非隐藏文件,但不匹配当前目录或其父目录。
The best way is probably to use two separate patterns, one of which matches the hidden files, and one which matches the non-hidden files.
One way to do this is
.* *
. However, this matches the directory itself.
and parent..
as well, which is usually not what you want.A pattern which avoids this problem is
.??* *
. Suppose you have the following files in your directory.As you can see in the example below, this glob pattern matches both hidden files and non-hidden files, but not the current directory or its parent.