Anonymous user
Walk a directory/Recursively: Difference between revisions
→{{header|Python}}: put back fnmatch,filter and add a link to its explanation
(→{{header|Python}}: First example changed to work on Python 3.x too) |
(→{{header|Python}}: put back fnmatch,filter and add a link to its explanation) |
||
Line 1,267:
{{works with|Python|2.3+}}
This uses the standard [http://docs.python.org/py3k/library/os.html?highlight=os.walk#os.walk os.walk()] module function to walk a directory tree, and the [http://docs.python.org/py3k/library/fnmatch.html fnmatch] module for matching file names.
<lang python>import
import os
rootPath = '/'
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
{{works with|Python|<nowiki>2.x</nowiki>}}
|