import os

import tables as tb
from tables.nodes import filenode

BASEDIR = '/path/to/dir'

h5file = tb.openFile('basedir.h5', 'w')

for root, dirs, files in os.walk(BASEDIR):
    grp = os.path.relpath(root, BASEDIR) if root != BASEDIR else ''
    grp = os.path.join('/', grp)
    print grp

    for d in dirs:
        h5file.createGroup(grp, d)

    for f in files:
        fnode = filenode.newNode(h5file, where=grp, name=f)
        with open(os.path.join(root, f), 'r') as fdisk:
            contents = fdisk.read()
        fnode.write(contents)
        fnode.close()

h5file.close()
