I have many HDF5 files in a directory and I want to concatenate all of them. I tried the following:
from glob import iglob
import shutil
import os
PATH = r'C:\Dropbox\data_files'
destination = open('data.h5','wb')
for filename in iglob(os.path.join(PATH, '*.h5')):
shutil.copyfileobj(open(filename, 'rb'), destination)
destination.close()
However, this only creates an empty file. Each HDF5 file contains two datasets, but I only care about taking the second one (which is named the same thing in each) and adding it to a new file.
Is there a better way of concatenating HDF files? Is there a way to fix my method?