newbie question :file handling

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

  1. harshu010

    harshu010

    Joined:
    May 23, 2008
    Messages:
    10
    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. 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. Kelly B

    File Handling (Newbie)

    Kelly B, Mar 29, 2007, in forum: C Programming
    Replies:
    9
    Views:
    410
    Flash Gordon
    Mar 30, 2007
  2. harshu010
    Replies:
    0
    Views:
    228
    harshu010
    May 25, 2008
  3. Mark Tarver
    Replies:
    22
    Views:
    1,310
    J Kenneth King
    Apr 26, 2009
  4. Peter
    Replies:
    34
    Views:
    1,940
    James Kanze
    Oct 17, 2009
  5. Iñaki Baz Castillo
    Replies:
    1
    Views:
    190
    Iñaki Baz Castillo
    Apr 15, 2008
Loading...

Share This Page