如何用单个Glob表达式匹配子目录级@c8y目录内容
Solution for Targeted Glob Matching
Got it, let's nail down that single glob expression you need. The core goal here is to only match @c8y directories that sit at least one level deep (not directly in the root), while excluding the root-level @c8y/apps and @c8y/client.
The Working Glob Expression
**/*/@c8y/**
Why This Works
Let's break it down piece by piece:
**: Matches any number of directories (including zero, but we pair it with*to force at least one parent folder)*: Requires exactly one directory segment before@c8y—this is the critical piece that rules out root-level@c8yentries@c8y/: Targets the specific subdirectory we want to match**: Matches any files or nested subdirectories inside the targeted@c8yfolder
Testing Against Your Paths
- ❌ Excluded:
@c8y/apps,@c8y/client(no parent directory exists before@c8y, so the*segment can't find a match) - ✅ Matched:
project-a/@c8y/client,project-b/@c8y/client,foo/@c8y/client, and all other nested@c8yentries (each has a parent directory that the*segment captures)
Why Your Previous Attempts Failed
**/@c8y/**: This matches root-level@c8ydirectories because**can resolve to an empty path—so it effectively becomes@c8y/**for root entries, which is exactly what you wanted to avoid.{!,**/}@c8y/**: This syntax doesn't properly enforce the parent directory requirement in most glob parsers. It's not a valid way to exclude root-level matches while including nested ones.
Quick Note
This works in most modern glob implementations (like Node.js's glob package, or tools that use it such as Webpack, Rollup, etc.). If you're using a more minimal glob parser, double-check that it supports the ** wildcard for recursive matching.
内容的提问来源于stack exchange,提问作者Glenn Mohammad
相关产品推荐
相关产品推荐

