Usage :
python merger.py result.txt
如果是在Linux环境下 :
cat ./* > result.txt
import os
import sys
import platform
# config-start
resultFileName = "result.txt"
# config-end
if platform.system() == "Windows":
separator = "\\"
else:
separator = "/"
root = "." + separator
scriptpath = sys.argv[0]
scriptfilename = scriptpath.split(separator)[-1]
files = []
for i in os.listdir(root):
if os.path.isfile(os.path.join(root,i)):
files.append(i)
if resultFileName in files:
files.remove(resultFileName)
if scriptfilename in files:
files.remove(scriptfilename)
print files
resultFile = open(resultFileName,"w")
for file in files:
tempFile = open(file,"r")
for line in tempFile:
resultFile.write(line)
resultFile.close()