Reputation: 1318
I've a directory structure as follows:
source
├── _assets
│ ├── css
│ └── js
├── _config.yaml
├── downloads
│ ├── hello2.txt
│ └── hello.txt
├── hello_world
│── robots.txt
└── favicon.ico
I'm using the node package glob to list files that follow a certain pattern. I want to list all files that are not in a folder whose name starts with an underscore ![_*]. The patterns I've tried include various combinations of
const pattern1 = `${sourceDirPath}/!(_*)**`
const pattern2 = `${sourceDirPath}/!(_*)/**`
pattern1
only gives me files like [source/robots.txt, source/favicon.ico]
whereas pattern2
only gives me files like [source/downloads/hello.txt, source/downloads/hello2.txt]
Can anyone give me some hint which pattern will let me have files from both patterns? Or do I have to look for both patterns and then merge the list?
Upvotes: 2
Views: 2414
Reputation: 1318
Solved by using ignore
const pattern = `${sourceDirPath}/**`;
const ignorePattern = `${sourceDirPath}/_*/**`;
glob(pattern, {
ignore: [ignorePattern],
nodir: true,
}, callback);
Upvotes: 2