简体   繁体   English

包括隐藏文件在内的所有内容的 Glob 模式

[英]Glob pattern for everything including hidden 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.更具体的背景:我想使用归档器库创建一个包含除node_modules (可能还有其他一些文件)之外的所有文件的归档文件。

archive.directory("???", {
    ignore: ["node_modules/", ...some other files],
});

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.和 parent ..也是如此,这通常不是你想要的。

A pattern which avoids this problem is .??* * .避免此问题的模式是.??* * Suppose you have the following files in your directory.假设您的目录中有以下文件。

file1  file2  .hidden

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.正如您在下面的示例中所见,此 glob 模式匹配隐藏文件和非隐藏文件,但不匹配当前目录或其父目录。

$ ls -l .??* *
-rw-r--r-- 1 amy users 0 Jul 30 18:00 file1
-rw-r--r-- 1 amy users 0 Jul 30 18:00 file2
-rw-r--r-- 1 amy users 0 Jul 30 18:00 .hidden

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

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