Skip to content

Instantly share code, notes, and snippets.

@Sulkar
Last active August 12, 2017 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sulkar/353800782edac2a066553551774e3b3f to your computer and use it in GitHub Desktop.
Save Sulkar/353800782edac2a066553551774e3b3f to your computer and use it in GitHub Desktop.
[python] merge files in folder
import shutil, os
# Function: merge files in current _dataDir folder!
def mergeFiles(_dataDir, _finalFileName):
if _dataDir == "":
print("Error no path available")
else:
# output Filename
outfilename = os.path.join(_dataDir, _finalFileName)
# open all .htm files and merge them to the outfilename
with open(outfilename, 'wb') as outfile:
for filename in os.listdir(_dataDir):
customEnding = ".htm"
if filename.endswith(customEnding):
tempFileName = os.path.join(dataDir, filename) # filename with dataDir
if tempFileName == outfilename:
# don't want to copy the output into the output
continue
with open(tempFileName, 'rb') as readfile:
shutil.copyfileobj(readfile, outfile)
Print("-> All " + customEnding + " files merged into: " + _finalFileName + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment