Using Common Wildcard Characters
In the previous lesson, you’ve learned that you can use the
.glob() method to basically search for files or folders inside of a directory. And you also got introduced to the
* character as a wildcard character that you can use to match any character. Now, there’s a couple of other ones that you’re going to learn about in this course.
Let me show them to you. Those are some common wildcard characters that you can use in search patterns for
.glob(). The first one is the
*, which matches any number of characters, then the
? matches a single character, any single character, and then you can use the
 and then put characters inside there, and it’s going to match any one of those characters that are inside of the brackets, but not any others. That might seem a little abstract, so let’s try it out with doing a couple of filter searchers inside of a directory.
00:52 But before you’re actually going to go filter for files and directories in the folder, let’s head back over to IDLE and create a couple more of them so that there’s more to filter and search for.
Navigate back to your notes directory and then create a couple more files. You can copy this code from the description of this lesson as well if you don’t want to type it out. Once you have the list assigned to
paths, you can say
for path in paths:
and then just
.touch() each of those files to create them.
01:34 After running the commands in IDLE, you should come up with a folder structure that looks like this.
Once you have this folder structure, you’re ready to do some searches within that folder structure using
.glob(), and you’ll do that starting in the next lesson.
Become a Member to join the conversation.