import glob print 'Named explicitly:' for name in glob.glob('dir/subdir/*'): print '\t', name print 'Named with wildcard:' for name in glob.glob('dir/*/*'): print '\t', name
Here is what the above code is Doing:
1. The glob.glob() function takes a pattern and returns a list of the files in the working directory that match that pattern.
2. The * characters are called wildcards, and you can use them to replace one or more characters in a string of characters.
3. The ? character is similar to the * character, but instead of representing zero or more characters, it represents only a single character.
4. The [ ] characters are used to match any character that is within a set of characters, for example, [abc] matches any character a, b, or c.
5. The [! ] characters are used to exclude specific characters, for example, [!abc] matches any character except a, b, and c.