erk, Bug? ( long post )

Sean Blakey sblakey at freei.com
Mon Jun 26 20:03:30 EDT 2000


I get a different message on my FreeBSD laptop:
OSError: [Errno 2] No such file or directory.

What is happening is that you are using chdir() to move in to each directory you
check, then calling os.listdir() on the relative path from where you started the
script.

I have attatched a modified version of your script that might clarify this.  The
only modification I made was the os.getcwd() call on line 58.

I suggest seeing if you can work without the os.chdir() calls (or maybe seeing
if you can get the job done with os.path.walk()).
        -Sean

On Mon, Jun 26, 2000 at 07:28:51PM -0400, David Broadwell wrote:
> All of my text is at the bottom...
> 
    <<Source of grope.py snipped by Sean Blakey>>
> 
> ERROR:
> Good morning Dave.
> Checking ( dir ): .
> Checking ( files ): .
> ['DLLs', 'Lib', 'libs', 'include', 'Tools', 'Doc', 'source']
> Crossing the bridge of death (while loop that falls off the net).
> Depth now at: 0 (how many directories deep am i? .. fails)
> Scan path for subdir loop ['DLLs', 'Lib', 'libs', 'include', 'Tools',
> 'Doc', 'source']
> Checking ( dir ): DLLs
> Checking ( files ): DLLs
> Checking ( dir ): Lib
> Checking ( files ): Lib
> Checking ( dir ): libs
> Checking ( files ): libs
> Checking ( dir ): include
> Checking ( files ): include
> Checking ( dir ): Tools
> Checking ( files ): Tools
> Checking ( dir ): Doc
> Checking ( files ): Doc
> Checking ( dir ): source
> Checking ( files ): source
> Checking ( dir ): Lib/Plat-Win
> Checking ( files ): Lib/Plat-Win
> Traceback (innermost last):
>   File "C:\PROGRA~1\PYTHON\TOOLS\IDLE\ScriptBinding.py", line 131, in
> run_module_event
>     execfile(filename, mod.__dict__)
>   File "C:\WINDOWS\Profiles\mongoose\Desktop\grope.py", line 112, in ?
>     main()
>   File "C:\WINDOWS\Profiles\mongoose\Desktop\grope.py", line 29, in main
>     file(dir)
>   File "C:\WINDOWS\Profiles\mongoose\Desktop\grope.py", line 63, in file
>     filetemp = os.listdir(filepath)
> OSError: [Errno 3] No such process
> 
> Is there a reason that that wrror message fills me with dread? Why is
> the interpreter punishing me? What did i do wrong?
> 
> It always dies on the first use of the files that calls a directoy that
> has a subpath. I tested that ability alone in the interpreter and it
> worked perfectly well. I am on python 1.5.2 on a windows 98 box. I did
> see aome comments on DejaNews about it, and it was also involving
> os.listdir.. But there was only one instance, and i do not see precisely
> how they relate...
> 
> -- 
>         ~We're all fallen angels who've forgotten how to fly~
>         Remember how: http://www.cyber-action.com/oed/dbroadwell.html
> --
> -- 
> http://www.python.org/mailman/listinfo/python-list

-- 
Sean Blakey, sblakey at freei.com
Software Developer, FreeInternet.com
(253)796-6500x1025
The trouble with computers is that they do what you tell them, not what
you want.
		-- D. Cohen
-------------- next part --------------
import os

filelist = []
subdirlist = []
filetype = 'm3u'
output = 'out.txt'

def main():
    stop = 2
    depth = 0
    path = '.'
    scan(path)
    file(path)
    print subdirlist
    if (subdirlist):
       print 'Crossing the bridge of death.'
       while (depth <= stop):
           print 'Depth now at:',
           print depth
           depth = depth + 1
           temp = []
           print 'Scan path for subdir loop',
           print subdirlist
           if (subdirlist):
              temp = subdirlist
              for dir in temp: 
                  scan(dir)
                  file(dir)
              print 'recycling while loop, wish me luck.'
       else: 
#           print 'Stopping that while loop variable readout: '
#           print 'This is where merge will be called once stable'
           print 'Filelist:',
           print filelist
#           print 'Subdirlist:',
#           print subdirlist
#           print 'Last depth:',
#           print depth
           print 'Stop set at:',
           print stop

def scan(scanpath):
    print 'Checking ( dir ):',
    print scanpath
    os.chdir(scanpath)
    dirtemp = os.listdir('.')
    for item in dirtemp:
        if (os.path.isdir(item)):
           if (scanpath == '.'): 
              subdirlist.append(item)
#              print 'Added: ' +item+ ' to subdirlist'
           else: 
              subdirlist.append(scanpath + '/' + item)
#              print 'Added: ' +(scanpath + '/' + item)+ ' to subdirlist'
    if (not(scanpath == '.')): os.chdir('..')

def file(filepath):
    print 'Checking ( files ) from', os.getcwd(),':',
    print filepath
    filetemp = os.listdir(filepath)
    for item in filetemp:
        for x in range(len(item)):
            if (item[x:(x+1)] == '.'):
               if (item[(x+1):] == filetype):
                  if (filepath == '.'):
                     filelist.append(item)
                     print 'Added: ' +item+ ' to filelist'
                  else: 
                     filelist.append(filepath + '/' + item)
                     print 'Added: ' +(filepath + '/' + item)+ ' to filelist'

def merge(filelist):
    if (filelist):
       print 'Sory dave actually merging the functions is disabled'
#       outbuffer=open(output,'w')
#       for item in filelist:
#           inbuffer=open(item)
#           outbuffer.write(inbuffer.read())
#           inbuffer.close()
#       outbuffer.close()
       print 'But if you want to know, I would have:'
       print 'Merged files:',
       print filelist
       print 'With:',
       print './' + output
    else:
       print 'No ' + filetype + ' files to process, Exiting...'

print 'Good morning Dave.'
main()


More information about the Python-list mailing list