lists and files question

Sean 'Shaleh' Perry shalehperry at comcast.net
Tue Jul 22 20:37:43 EDT 2003


On Tuesday 22 July 2003 16:57, hokiegal99 wrote:
> This code:
>
> import os, re, string
> setpath = raw_input("Enter the path: ")
> for root, dirs, files in os.walk(setpath):
> 	id = re.compile('Microsoft Excel Worksheet')
> 	fname = files
> #	print fname
> 	content = open(fname[1],'rb')
>
> Produces this error:
>
> IOError: Error[2] No such file or directory 'Name of File'
>

if you replace your logic with some prints you will quickly see the problem.

What happens is os.walk() passes filenames without their path.  You need to 
use os.path.join() to get the full name back.






More information about the Python-list mailing list