Read HDF5 with variable number of keys

I get HDF5 files of a measurement. These files are organized like [key_lvl1][key_lvl2][...].
The structure in the deeper levels is always the same.
However, the first key level is a simple counter for the number of measurements stored in that specific file, e.g. key_lvl1 = ["entry_1"], ["entry_2"] and so on.
Now I would like to read the whole file. For this I would have to specify the string of key_lvl1 for all the entries - with out knowing it.

How can I read a HDF with out knowing all the key_lvl1 strings in advance?

If there aren’t any other entries in the first level, you can use

using HDF5
f = h5open(fname)
lvl1keys = names(f)

data = [f[joinpath(key, "rest/of/path")] for key in lvl1keys]
1 Like

Note that names() has been renamed to keys, so the working example now would be

using HDF5
f = h5open(fname)
lvl1keys = keys(f)

data = [f[joinpath(key, "rest/of/path")] for key in lvl1keys]
2 Likes

Thanks for the update!