我的目录结构如下:
source
├── _assets
│ ├── css
│ └── js
├── _config.yaml
├── downloads
│ ├── hello2.txt
│ └── hello.txt
├── hello_world
│── robots.txt
└── favicon.ico
我使用节点包glob列出遵循特定模式的文件。我想列出所有不在名称以下划线开头的文件夹中的文件![_ *]。我尝试的模式包括
的各种组合const pattern1 = `${sourceDirPath}/!(_*)**`
const pattern2 = `${sourceDirPath}/!(_*)/**`
pattern1
仅向我提供[source/robots.txt, source/favicon.ico]
等文件,而pattern2
仅向我提供[source/downloads/hello.txt, source/downloads/hello2.txt]
任何人都可以给我一些提示,哪种模式会让我从两种模式中获取文件?或者我是否必须查找这两种模式然后合并列表?
答案 0 :(得分:1)
使用ignore
解决const pattern = `${sourceDirPath}/**`;
const ignorePattern = `${sourceDirPath}/_*/**`;
glob(pattern, {
ignore: [ignorePattern],
nodir: true,
}, callback);