8.4 Lists of files and folders
If I have the five file names
guitar_01.py
,
guitar_02.py
,
unipoly_01.py
,
unipoly_02.py
, and
unipoly_10.py
,
then I can use wildcard characters to match some of the names. Here are some examples:
- The pattern “
*.py
” matches all of them since the pattern means “the name may start with any characters but must end in “.py
’.” - The pattern “
*01*
” matchesguitar_01.py
andunipoly_01.py
. - “
unipoly_0?.py
” matchesunipoly_01.py
andunipoly_02.py
. The “?
” is a single character wildcard and matches anything in that one position.
Using patterns like these to match file names is called “globbing” and goes back to the early days of UNIX in the late 1960s and early 1970s. The glob module implements globbing in Python.
The module...