[Tutor] any help with this piece of code

Richard gelling uselinux34 at yahoo.co.uk
Thu May 12 21:57:36 CEST 2005


import os

fileList = []
subDirectories = []
directories = []
directoryPath = raw_input( "Type in the path you want to start at: " )

for directory,subDirectory, files in os.walk( directoryPath ):
    directories.append( directory )
    subDirectories.append( subDirectory )
    fileList.append( files )

for Files in fileList:
    print Files

# It works fine up until here

fileToSearchFor = raw_input( "Type in the file name you want to search 
for: ")

if fileToSearchFor in fileList:
    print "%s was found" % fileToSearchFor
else:
    print "%s was not found" % fileToSearchFor

Could someone explain to me why this pice of code doesn't work, in that 
it works fine up until where I have commented , but when I come to 
search the list for a file name, even though I know the filename is in 
that particular directory, and is present in the list returned by 
'fileList.append( files )' it always reports that the file is not found. 
Incidentally if you try this code out, when prompted for the path to 
start at, don't select a large directory as it takes sometime to run. It 
may not be very useful I am just curious as to why the file name cannot 
be found in the list, what am I missing?

Richard Gelling
    



More information about the Tutor mailing list