Daniel Roy Greenfeld

Daniel Roy Greenfeld

About | Articles | Open Source | Books | Tags | Search

TIL: Finding and ignoring files with Glob

How to find and ignore files and directories when using glob

Glob is a really handy tool for finding filepaths. It resembles regular expressions but the syntax is different. Finding matches is easy:

# finds python files in the current working directory
*.py
# finds all the nested python files.
**/*.py

What I didn't know until today is how to exclude files. That's done through the use of the ! operator. So the inverse of the above is:

# finds anything but python files in the current working directory
*.[!py]*
# finds anything but python files in the nested directory 
- **/*.[!py]*
Today I Learned

Tags: TIL

← Back to all articles

Search