need insight...

David Broadwell dbroadwell at mindspring.com
Sat Jun 24 03:45:35 EDT 2000


The code to follow, to what i know, is behaving erratically. it is
erratic in that in the section after the print 'checking... statement
the  'for item in directorylist:' seems to be skipping over entries in
it's list for no apparent reason... (note: what is skipps changes if the
list it is given chages, but from what i can tell, it always skips about
half of the things on the list. i have snipped out as much of the code
as i can and still leave it psudo functional..

I am seeking help in some capacity, and if i have commited some grevious
programming error, enough information to avoid it in the future..

If it dosen't demonstate the same problem i will post the code entire
(it is about 60 lines)

thanks!

# Code follows..

import os
import sys

filetype = 'm3u'
directorylist = []

def doit():
    cwd = []
    print 'reading current directory'
    cwd = os.listdir('.')
    print 'building directorylist'
    for item in cwd:
        if (os.path.isdir(item)):
           directorylist.append(item)
           cwd.remove(item)
    del cwd
    print 'Checking for subdirectories to check.'
    print directorylist
    for item in directorylist:
        print 'subdirectory ' + item + ' found, scanning.'
        os.chdir(item)
        subdir = []
        subdir = os.listdir('.')
        print subdir
        for thing in subdir:
            print thing,
            if (thing[(len(thing)-3):] == filetype):
               print 'Yup.'
               # join item(path) to file
               # add to filelist
            else: 
               print 'Nope.'
               subdir.remove(thing)
        print subdir
        del subdir
        os.chdir('..')
      
doit()

-- 
        ~We're all fallen angels who've forgotten how to fly~
        Remember how: http://www.cyber-action.com/oed/dbroadwell.html
--



More information about the Python-list mailing list