Outils pour utilisateurs

Outils du site


python:programmes:find

Ceci est une ancienne révision du document !


Chercher un fichier ou dossier

import os, fnmatch

def locate(pattern, root=os.curdir):
    '''Locate all files matching supplied filename pattern in and below
    supplied root directory.'''
    for path, dirs, files in os.walk(os.path.abspath(root)):
        for filename in fnmatch.filter(files, pattern):
            yield os.path.join(path, filename)
>>> import glob
>>> glob.glob('./[0-9].*')
['./1.gif', './2.txt']
>>> glob.glob('*.gif')
python/programmes/find.1329337455.txt.gz · Dernière modification : 2012/02/15 20:24 de root