Python简单读写-边读边写
程序员文章站
2024-03-21 19:29:10
...
import os
def traverse(f):
with open('D:/morefuncode.txt', 'a', encoding='UTF-8') as h:
fs = os.listdir(f)
for f1 in fs:
tmp_path = os.path.join(f, f1)
if not os.path.isdir(tmp_path):
with open(tmp_path, 'r', encoding='UTF-8') as g:
fa = g.readlines()
h.writelines(fa)
h.write('\n')
else:
traverse(tmp_path)
path = 'D:/morefun-android/app/src/main/java/com'
traverse(path)
遍历文价夹下所有文件,写到一个文件中。Python代码量是真真真真少啊!