I have thousands of text files in a directory, and would like to save the content of each file in a list (one big file-list) while maintaining the order of the files as they are in the directory. The texts are not to be concatenated. Please see example of my desired output.
Example=['textual content of file one', 'textual content of file two', 'textual content of file three'.....textual content of file n]
My attempt:
filelist=[file-1,file-2,...file-n]
destinationfile="C:\\XXXXX\\dump_large_json.txt"
with open(destinationfile, 'w',encoding='utf-8') as f:
for file in filelist:
with open(file, 'r') as f2:
h=json.dump(f2,f)
output:
TypeError: Object of type 'TextIOWrapper' is not JSON serializable
Any ideas on how to serially dump text files in json format would be appreciated.