不在以下划线开头的文件夹中的文件的节点 glob 模式
node glob pattern for files not in folders starting with underscore
我的目录结构如下:
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]
这样的文件
谁能给我一些提示,哪种模式可以让我同时拥有两种模式的文件?还是我必须寻找两种模式然后合并列表?
使用忽略解决
const pattern = `${sourceDirPath}/**`;
const ignorePattern = `${sourceDirPath}/_*/**`;
glob(pattern, {
ignore: [ignorePattern],
nodir: true,
}, callback);
我的目录结构如下:
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]
谁能给我一些提示,哪种模式可以让我同时拥有两种模式的文件?还是我必须寻找两种模式然后合并列表?
使用忽略解决
const pattern = `${sourceDirPath}/**`;
const ignorePattern = `${sourceDirPath}/_*/**`;
glob(pattern, {
ignore: [ignorePattern],
nodir: true,
}, callback);