时间:2021-07-01 10:21:17 帮助过:18人阅读
代码如下:
import sys, os
def readFile(filename):
file=open(filename, "r")
s=file.read().strip()
file.close()
return s
def writeFile(filename, files):
content=[]
for f in files:
print "reading file ' %s ' " % f
s=readFile(f)
print "read file ' %s ' completed" % f
content.append(s)
print "writing file ' %s ' " % filename
file=open(filename, "w")
file.write("\n/*-----This is a seperating line.-----*/\n".join(content))
file.close()
print "write file ' %s ' completed" % filename
filters=['.txt']
fullpath=os.getcwd();
print "opening directory: ' %s ' " % fullpath
sys.path.append(fullpath)
files = os.listdir(fullpath)
files =[f for f in files if os.path.splitext(f)[1].lower() in filters]
writeFile("beaunet_be_card.sql", files)