Hello Christian, I think that you want to do something like the following, which uses os.walk():
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() Note that you can use add other features like storing the status of the file (os.stat()) as an attribute of each file, if you wanted to get fancy. Also note that this includes filenames with '.' in them, which throws a lot of natural naming warnings. You can always suppress these, using the standard library warnings module. Perhaps this should be an example.... Be Well Anthony On Wed, Jul 25, 2012 at 1:30 PM, Christian Werner < freizeitbeauftrag...@googlemail.com> wrote: > Hi group > > I'm currently trying to store a directory with all files contained as > filesNodes in a h5 file. The reason is that I currently store a single > configuration file and model output from this model as tables in one h5 > file to a) document the simulation settings and b) store the model results. > > This works and everything is fine, but I was wondering if there is some > elegant way to just copy a set of files/ subfolders into the h5 and also > store the filenames, attributes et al. ... > It would be even better if I could store my entire model setup (incl. the > model executable), too, as this would really mean I or someone else would > always be sure that I/ he could reproduce the shared data with the original > model setup)... > > Consider this file structure (should be copied as file nodes), in addition > there will be tables storing the model results...: > > -+- model (binary) > | > +- setupdir, contains fileA, fileB, ... > | > +- parameterdir, contains parA, parB, ... > > Is it possible to just copy them without knowing a) filenames, b) number > of files, ...? Without specifying each file, creating a node etc? > Is there some API for this? > > Cheers, > C > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Pytables-users mailing list > Pytables-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/pytables-users > >
walk.py
Description: Binary data
------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users