Random Problems
Hrvoje Niksic
hniksic at xemacs.org
Wed Aug 13 02:40:04 EDT 2008
"Lanny" <lanny at freshells.ch> writes:
> Well the othe day I was making a program to make a list of all the
> songs in certian directorys but I got a problem, only one of the
> directorys was added to the list. Heres my code:
>
> import random
> import os
> import glob
If you need recursive traversal of directories, try os.walk. For
example:
mp3s = []
for root, subdirs, files in os.walk(r'C:\Documents and Settings\Admin\My Documents\Downloads'):
for f in files:
if f.endswith('.mp3'):
mp3s.append(os.path.join(root, f))
# mp3s is now a list of mp3 files under
# C:\Documents and Settings\Admin\My Documents\Downloads
More information about the Python-list
mailing list