Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Using Common Wildcard Characters

00:00 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.

00:17 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.

01:05 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:

01:25 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.

01:42 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.