newbie question :file handling

Joined
May 23, 2008
Messages
10
Reaction score
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top