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.
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.