Last active
August 12, 2017 20:09
-
-
Save Sulkar/353800782edac2a066553551774e3b3f to your computer and use it in GitHub Desktop.
[python] merge files in folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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