Jump to content

Walk a directory/Recursively: Difference between revisions

→‎{{header|Python}}: First example changed to work on Python 3.x too
(→‎{{header|Python}}: First example changed to work on Python 3.x too)
Line 1,264:
 
=={{header|Python}}==
{{works with|Python|3.x}}
{{works with|Python|2.3+}}
 
This uses the standard ''os.walk()'' "[[generator]]".
 
<lang python>import fnmatchos
import os
 
rootPath = '/'
extension = '.mp3'
pattern = '*.mp3' # Can include any UNIX shell-style wildcards
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
if print osfilename.path.joinendswith(root, filenameextension)</lang>:
print( os.path.join(root, filename))</lang>
 
{{works with|Python|<nowiki>2.x</nowiki>}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.