>>> import glob
>>> dir(glob)
['__all__', '__builtins__', '__doc__', '__file__', '__name__', 'fnmatch', 'glob', 'glob1', 'has_magic', 'magic_check', 'os', 're']
>>> help(glob)
Help on module glob:
NAME
glob - Filename globbing utility.
FILE
d:/python24/lib/glob.py
FUNCTIONS
glob(pathname)
Return a list of paths matching a pathname pattern.
The pattern may contain simple shell-style wildcards a la fnmatch.
DATA
__all__ = ['glob']
它的主要方法就是glob,用它在指令碼中處理一批檔案名稱非常方便,樣本如下:
>>> glob.glob("c://")
['c://']
>>> glob.glob("c://*")
['c://arcldr.exe', 'c://arcsetup.exe', 'c://boot.ini', 'c://bootfont.bin', 'c://cmd.txt', 'c://COMMAND.COM', 'c://CONFIG.SYS', 'c://debug_trace.txt', 'c://DevTools', 'c://DFIMB.DAT', 'c://Documents and Settings', 'c://Intel', 'c://IO.SYS', 'c://MSDOS.SYS', 'c://MSOCache', 'c://NTDETECT.COM', 'c://ntldr', 'c://PAGEFILE.SYS', 'c://Program Files', 'c://Recycled', 'c://RECYCLER', 'c://response.txt', 'c://rt', 'c://SUHDLOG.DAT', 'c://System Volume Information', 'c://useprint.bat', 'c://VIDEOROM.BIN', 'c://WINDOWS', 'c://wmpub', 'c://WUTemp']
>>> glob.glob("c://*.txt")
['c://cmd.txt', 'c://debug_trace.txt', 'c://response.txt']