Walking recognized structures

Chris Lyon chris.lyon at spritenote.co.uk
Mon Feb 9 13:56:20 CET 2004


I handle a lot of audio files of different formats, which live in a
directory tree. WAV files in a wav directory, AIFF's in an AIFF
directory next to the wav directory and mp3's in an MP3 directory next
to the Aiff.

this directory structure exists under a large directory tree of the
libraries the sounds are in.

Whenever I wish to add a new file format I find the syntax of
os.listdir & especially os.path.walk particularly clumsy. as I am
constantly rebuilding directory path's with join and still requiring
to add extensions by hand + '.' +'MP3' for instance. the syntax on one
line can become very large what with the requirement to re cement the
directory path on to the file name.
I would love to able to just write a simple visit routine that just
does the processing I require but the all the work in visit seems to
end up as case checking ('WAV's arrive as Wav , 'WAV' and every other
possible combination), and frantic tearing apart of reasonably large
file path's I have built myself to actually allow me to run the
ConvertWAVtoMp3(wavfilepointer, mp3destination,
mp3destinationfilename) that does the real work.

Do people have any suggestions for how I might implement this in a
dirwalker routine that allows me to simply add the appropriate
ConvertWAVtoMP3 like function that I can emerge at the end of
unfrazelled and wondering quite how that version worked as opposed to
all the other that fell over half way through for some obscure path
reason ? (why oh why do people insist on putting spaces and worse
tildes in path names in the Windows world?).

I know there is a new os.walk() but since I'm still trying to get my
head round the existing versions and I'm sort of locked to 2.1 for
this application(Oracle DC2 drivers don't seem to like anything after
2.1).

Could anyone describe a method for what I feel must be a fairly
regularly encountered problem?

I would post my efforts but since they are awash with prints, asserts
and other chunks of desperate debugging I feel this would tend to
generate humour which I know is a gain for all, but I have a shred of
integrity that I would like to maintain and laughter might just have
me walking off stage left, but probably tripping over a '/' on the
way.



More information about the Python-list mailing list