copying files into one

Gary Wessle phddas at yahoo.com
Sun May 14 06:09:10 CEST 2006


Hi

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.

thanks


combined = open(outputFile, 'wb')

for name in flist:
    if os.path.isdir(file): continue
    
    infile = open(os.path.join(file), 'rb')

    # CODE 1 this does not work
    tx = infile.read(1000)
    if tx == "": break
    combined.write(tx)
    infile.close()
    
    # CODE 2 but this works fine 
    for line in infile:
        combined.write(line)
    infile.close()
    
combined.close()



More information about the Python-list mailing list