Need help: Compiling Python-Code &In-Reply-To=

Discussion in 'Python' started by CRAIG DALTON, May 2, 2008.

  1. CRAIG DALTON

    CRAIG DALTON Guest

    Hi,

    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.

    Thanks,

    Craig Dalton
    Business Applications Systems Analyst
    Sentara Healthcare Systems
    Information Technology
     
    CRAIG DALTON, May 2, 2008
    #1
    1. Advertising

  2. En Fri, 02 May 2008 18:39:36 -0300, Larry Bates <`>
    escribió:

    > No real reason to get shutil involved in this.


    ....except memory usage; shutil.copyfileobj reads the input in chunks, but
    your version reads the whole file in memory. Depending on the file sizes,
    this might be an issue.

    --
    Gabriel Genellina
     
    Gabriel Genellina, May 2, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeffrey Silverman

    OT: Just venting, no need to reply.

    Jeffrey Silverman, Nov 9, 2004, in forum: HTML
    Replies:
    18
    Views:
    760
    Toby Inkster
    Nov 12, 2004
  2. Carsten Heesch

    Need help: Compiling Python-Code

    Carsten Heesch, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    304
    Carsten Heesch
    Jul 15, 2003
  3. Thomas Buschhardt

    Re: Need help: Compiling Python-Code

    Thomas Buschhardt, Jul 15, 2003, in forum: Python
    Replies:
    2
    Views:
    795
    Carsten Heesch
    Jul 15, 2003
  4. davidj411
    Replies:
    1
    Views:
    1,131
    Mike Driscoll
    May 27, 2008
  5. Replies:
    2
    Views:
    602
Loading...

Share This Page