copying files into one

Edward Elliott nobody at 127.0.0.1
Sun May 14 07:05:39 CEST 2006


Gary Wessle wrote:

> I am looping through a directory and appending all the files in one
> huge file, the codes below should give the same end results but are
> not, I don't understand why the first code is not doing it.
> 
> combined = open(outputFile, 'wb')
> for name in flist:
>     if os.path.isdir(file): continue
>     infile = open(os.path.join(file), 'rb')

this shouldn't work.  'file' is a type object, not a filename.  did you
rebind 'file' without showing us?  or should those 'file's be 'name's
instead?  in either case, calling os.path.join with one argument is
pointless.

 
>     # CODE 1 this does not work
>     tx = infile.read(1000)
>     if tx == "": break
>     combined.write(tx)
>     infile.close()

hint: where will break take you?  therein lies your answer.


-- 
Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net



More information about the Python-list mailing list