newbie question :file handling

Discussion in 'Python' started by harshu010, May 26, 2008.

  1. harshu010

    harshu010

    Joined:
    May 23, 2008
    Messages:
    10
    Likes Received:
    0
    Hi all,
    I want to write the list of files in a directory and subdirectory into a text file.
    I am able to print the files as output. But i want to write them to a file.
    Please help me .Its very urgent.
    The following is the code i am using:
    import os
    path="D:\\harshu\\p3 related docs\\p3 related docs" # insert the path to the directory of interesthere
    dirList=os.listdir(path)
    for fname in dirList:
    f=file("trial.txt",'w')
    f.writelines(fname)
    f.close()
    I am getting the output as a display:
    but i want it to be written to a file.
     
    harshu010, May 26, 2008
    #1
    1. Advertisements

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. Tom
    Replies:
    7
    Views:
    425
  2. Teuvo Eloranta

    newbie list handling question

    Teuvo Eloranta, Jan 13, 2004, in forum: Python
    Replies:
    1
    Views:
    376
    Diez B. Roggisch
    Jan 13, 2004
  3. Niki Iv
    Replies:
    6
    Views:
    447
    Tim Roberts
    Feb 12, 2004
  4. luke
    Replies:
    3
    Views:
    333
    Cowboy \(Gregory A. Beamer\)
    Oct 6, 2006
  5. Kelly B

    File Handling (Newbie)

    Kelly B, Mar 29, 2007, in forum: C Programming
    Replies:
    9
    Views:
    555
    Flash Gordon
    Mar 30, 2007
  6. harshu010
    Replies:
    0
    Views:
    308
    harshu010
    May 25, 2008
  7. Jerry C.
    Replies:
    8
    Views:
    586
    Uri Guttman
    Nov 23, 2003
  8. JasonGilbertUK

    Newbie with simple File handling problem

    JasonGilbertUK, Nov 14, 2006, in forum: Perl Misc
    Replies:
    3
    Views:
    213
    Uri Guttman
    Nov 14, 2006
Loading...