En Fri, 02 May 2008 17:45:57 -0300, CRAIG DALTON <[EMAIL PROTECTED]> escribió:

I'm looking to append several text files in one director and out put the combined files into another director. I'm new to Python and just can't get it to work. So far I've been able to create a file in the desired directory but it isn't pulling any of the data in the originating directory. Could please look at my code and tell me what I'm doing wrong.

import os,shutil
f=open("c:\\output\\testing1.txt","a+")
for r,d,fi in os.walk("c:\\test"):
    for files in fi:
        if files.endswith(".txt"):
            g=open(os.path.join(r+,files))
            shutil.copyfileobj(g,f)
            g.close()
f.close()

Any help would be great.

Except the spurious + in join(r+,files), and the usage of "files" denoting a single file name, the code looks OK to me. Try adding a few print statements, showing the files and directories it is processing.

(Note: Next time, if you want to post a NEW question, create a NEW thread instead of replying to any random post...)

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to