Exclude a folder from glob pattern matching
Here's the PR where that was merged. Here's the syntax. Here's what I have working in my package.json
:
"prettier-fix": "prettier --write \"**/*.{js,jsx,json,ts,tsx,md,mdx,css,html,yml,yaml,scss}\" \"!\\.next/**\""
Lint all matching except .next
directory. Note the quotes.
Globbing pattern: exclude a directory
Like this:
find /vol ! -path '*/form/*' -type f -name '*.txt'
If you need to negate a pattern, like with a regex, AFAIK look around are not supported by find -regex*
. So it's not possible only with one find
regex expression.
glob exclude pattern
The pattern rules for glob are not regular expressions. Instead, they follow standard Unix path expansion rules. There are only a few special characters: two different wild-cards, and character ranges are supported [from pymotw: glob – Filename pattern matching].
So you can exclude some files with patterns.
For example to exclude manifests files (files starting with _
) with glob, you can use:
files = glob.glob('files_path/[!_]*')
Shell globbing exclude directory patterns
Michael's answer is right. **
matches too much (greedy match), including assets
.
So, with this tree:
.
|-- a
| |-- a1
| | +-- assets
| | |-- a1-1
| | | +-- a1-1.js
| | +-- a1-2
| | +-- a1-2.js
| +-- a2
| +-- a2.js
|-- assets
| +-- xyz.js
|-- b
| |-- b1
| | +-- b1-2
| | +-- b1-2-3
| | |-- assets
| | | +-- b1-2-3.js
| | +-- test
| | |-- test2
| | | +-- test3
| | | +-- test4
| | | +-- test4.js
| | +-- test.js
| +-- b.js
|-- c
| +-- c.js
+-- x.js
The .js files are:
$ find . -name '*.js'
./x.js
./assets/xyz.js
./a/a2/a2.js
./a/a1/assets/a1-2/a1-2.js
./a/a1/assets/a1-1/a1-1.js
./c/c.js
./b/b.js
./b/b1/b1-2/b1-2-3/test/test2/test3/test4/test4.js
./b/b1/b1-2/b1-2-3/test/test.js
./b/b1/b1-2/b1-2-3/assets/b1-2-3.js
There is a bash variable GLOBIGNORE
to do exactly what you are trying to do.
So, this would work:
$ GLOBIGNORE='**/assets/**:assets/**:**/assets'
$ ls -1 **/*.js
a/a2/a2.js
b/b1/b1-2/b1-2-3/test/test2/test3/test4/test4.js
b/b1/b1-2/b1-2-3/test/test.js
b/b.js
c/c.js
x.js
Matching all files without an extension, excluding folders [Minimatch]
My current solution was to use a few patterns:
- one for the
"index"
- one for the
"404"
- one for any files without extensions within folders
"*/!(*.*)"
Recursively exclude files and folders that have names beginning with specific characters (using nodejs and glob)
Use ignore option of glob to exclude directories and files starting from character underscore
var glob = require('glob');
glob("**/*",{"ignore":['**/_**.pug', "**/_**/**"]}, function (err, files) {
console.log(files);
})
// Output
[
'Pages',
'Pages/Open',
'Pages/Open/EntryPoint.pug',
'Pages/Open/Top',
'Pages/Open/Top/EntryPoint.pug',
'Pages/Open/Top/SubDirectory1',
'Pages/Open/Top/SubDirectory1/NonPartial.pug',
'test.js'
]
Match all files that are inside a folder and ignore one folder inside
Try **/files/{*.js,!(folder1)*/*.js}
. You can test using globster.xyz
Related Topics
How to Insert Space Every 4 Characters for Iban Registering
Create Parent and Child Relationship Using Lodash
Callback Function Cannot Access Variable Within Parent Function'S Scope
Check Whether Elements from One Array Are Present in Another Array
Remove a Specific String from Url and Redirect
Prevent Bootstrap Modal Window from Closing on Form Submission
How to Display All Imagefrom Array in Reactjs
React Display Line Breaks from Saved Textarea
How to Handle Multiple Submit Buttons in a Form Using Angular Js
Bootstrap Datepicker Set Default Date Not Working
How to Append My Data in Nested Object
How to Detect the Mime Type of Data Url
Call JavaScript Function Onchange Event of Dropdown List
Javascript to Hide Multiple Div
Electron - How to Add External Files
Reinitialize/Reset Dropzone After Form Is Submitted