标签:open wal temp 目录 join 遍历文件 dell int def
import os
import sys
def delline(infile,outfile):
infopen = open(infile,"r",encoding="utf-8")
outfopen = open(outfile,"w",encoding="utf-8")
lines = infopen.readlines()
for line in lines:
if line.split():
outfopen.writelines(line)
else:
outfopen.writelines("")
infopen.close()
outfopen.close()
delline("index.html","temp.heml")
1 rootdir = 'F:\data'
2 list = os.listdir(rootdir) #列出文件夹下所有的目录与文件
3 for i in range(0,len(list)):
4 path = os.path.join(rootdir,list[i])
5 if os.path.isfile(path):
6 #你想对文件的操作
#使用os.walk方法遍历:
import os
path="D:\\Temp_del\\a"
for i in os.walk(path):
print(i)
标签:open wal temp 目录 join 遍历文件 dell int def
原文地址:https://www.cnblogs.com/csnd/p/10798023.html