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')
['1.gif', 'card.gif']
python/programmes/find.1363126697.txt.gz · Dernière modification : 2013/03/12 22:18 de root