我的代码是这样的,但问题是它仅在output.txt中提供了最后一个文件名,而不是全部30个文件名。
import os
path="path I wanted"
dirList=os.listdir(path)
for filename in dirList:
print (filename)
f = open("output1.txt", "w")
f.write(filename)
f.close()
“ w”标志“打开”在循环中的每次迭代中都将文件截断。如果文件已经存在,请改用'a'标志。有关更多信息,请参见此处。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句