Unit 11Globbing File Names and Other Strings

Globbing is the process of matching specific file names and wildcards, which are simplified regular expressions. A wildcard may contain the special symbols ’*’ (represents zero or more characters) and ’?’ (represents exactly one character). Note that ’\’, ’+’, and ’.’ are not special symbols!

The module glob provides a namesake function for matching wildcards. The function returns a list of all file names that match the wildcard passed as the parameter:

 glob.glob(​"*.txt"​)
=> ['public.policy.txt', 'big.data.txt']

The wildcard ’*’ matches all file names in the current directory (folder), except for those that start with a period (’.’). To match the special file names, use the wildcard ".*" ...

Get Data Science Essentials in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.