python's fnmatch&glob&os.listdir

[python's fnmatch&glob&os.listdir]

fnmatch:

  fnmatch只有4种special character,用于提供和shell中一样的文件名的匹配.

  python's fnmatch&glob&os.listdir

  For a literal match, wrap the meta-characters in brackets. For example, '[?]' matches the character '?'.

  主要函数有: fnmatch.fnmatch(), fnmatch.fnmatchcase(), fnmatch.filter(), fnmatch.translate()

  注意要点:

    1. '.'在fnmatch中只是一个普通的文件.

os.listdir:

  os.listdir提供类似于shell中的ls功能, 返回的列表只包含文件名, 默认不显示'.', '..'

glob:

  glob用于提供检索功能, 该功能的实现基于os.listdir & fnmatch. 返回的列表为cwd的相对路径.

  glob treats filenames beginning with a dot (.) as special cases. ('.' & '..' 在glob中会被解释为相应的路径)

  主要函数: glob.glob(), glob.iglob()

  注意: 

    If the directory contains files starting with . they won’t be matched by default. For example, consider a directory containing card.gif and .card.gif: 

    python's fnmatch&glob&os.listdir

 参考: 

 1. http://docs.python.org/2.7/library/glob.html#module-glob

 2. http://docs.python.org/2.7/library/fnmatch.html#fnmatch.fnmatch

 3. http://docs.python.org/2.7/library/os.html

你可能感兴趣的:(python)