I have many CSV files, and I want to them join then into one txt file, binary format..
The following code give the above error:
import os
from csv import reader
from csv import writer
CONST_DATA_DIR = "F:/Data/"
CONST_DATABIN_DIR = "F:/DataBinary/"
def createFilesArr():
filesArr = []
os.chdir(CONST_DATA_DIR)
for file in os.listdir("."):
if file.endswith(".csv"):
filesArr.append(file)
return filesArr
filesArr = createFilesArr()
newFileName = "oneBinaryFile.txt"
newFile = open(CONST_DATABIN_DIR + newFileName, 'wb')
for file in filesArr:
currentFile = open(CONST_DATA_DIR + file, 'r', newline='', encoding='UTF8')
newFile.write(currentFile.read())
currentFile.close()
newFile.close()
EDIT:
The CSV files are originally written as a txt type. In the other hand the merge file should be in the binary format.
The process of creating the CSV file is complicated, hence, if possible, I prefer to somehow convert the files before reading.
Any suggestions?