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:
Become a Member to join the conversation.