rootpy.io.Directory¶
-
class
rootpy.io.
Directory
(name, title=None, classname='', parent=None)[source]¶ A subclass of ROOT’s TDirectoryFile [1]
References
[R12] http://root.cern.ch/root/html/TDirectoryFile.html -
Close
(*args)¶ Like ROOT’s Close but reverts to the gDirectory before this file was opened.
-
cd_previous
()¶ cd to the gDirectory before this file was open.
-
close
(*args)¶ Like ROOT’s Close but reverts to the gDirectory before this file was opened.
-
copytree
(dest_dir, src=None, newname=None, exclude=None, overwrite=False)¶ Copy this directory or just one contained object into another directory.
Parameters: dest_dir : string or Directory
The destination directory.
src : string, optional (default=None)
If
src
is None then this entire directory is copied recursively otherwise ifsrc
is a string path to an object relative to this directory, only that object will be copied. The copied object can optionally be given anewname
.newname : string, optional (default=None)
An optional new name for the copied object.
exclude : callable, optional (default=None)
exclude
can optionally be a function which takes(path, object_name)
and if returns True excludes objects from being copied if the entire directory is being copied recursively.overwrite : bool, optional (default=False)
If True, then overwrite existing objects with the same name.
-
keys
(latest=False)¶ Return a list of the keys in this directory.
Parameters: latest : bool, optional (default=False)
If True then return a list of keys with unique names where only the key with the highest cycle number is included where multiple keys exist with the same name.
Returns: keys : list
List of keys
-
mkdir
(path, title='', recurse=False)¶ Make a new directory. If recurse is True, create parent directories as required. Return the newly created TDirectory.
-
objects
(cls=None)¶ Return an iterater over all objects in this directory which are instances of cls. By default, iterate over all objects (cls=None).
Parameters: cls : a class, optional (default=None)
If a class is specified, only iterate over objects that are instances of this class.
Returns: A generator over the objects in this directory.
Examples
$ rootpy browse myfile.root
In [1]: list(f1.objects(R.Directory)) Out[1]: [Directory(‘mydirectory’)]
-
rm
(path, cycle=';*')¶ Delete an object at path relative to this directory
-
walk
(top=None, path=None, depth=0, maxdepth=-1, class_ref=None, class_pattern=None, return_classname=False, treat_dirs_as_objs=False)¶ Walk the directory structure and content in and below a directory. For each directory in the directory tree rooted at
top
(includingtop
itself, but excluding ‘.’ and ‘..’), yield a 3-tupledirpath, dirnames, filenames
.Parameters: top : string, optional (default=None)
A path to a starting directory relative to this directory, otherwise start at this directory.
path : string, optional (default=None)
A path prepended as a prefix on the
dirpath
. This argument is used internally as the recursion traverses down through subdirectories.depth : int, optional (default=0)
The current depth, used internally as the recursion traverses down through subdirectories.
max_depth : int, optional (default=-1)
The maximum depth in the directory hierarchy to traverse. There is no limit applied by default.
class_ref : class, optional (default=None)
If not None then only include objects that are instances of
class_ref
.class_pattern : string, optional (default=None)
If not None then only include objects in
filenames
with class names that matchclass_pattern
.class_pattern
should be a Unix shell-style wildcarded string.return_classname : bool, optional (default=False)
If True, then each entry in
filenames
is a tuple of the form(filename, classname)
.treat_dirs_as_objs : bool, optional (default=False)
If True,
filenames
contains directories as well.Returns: dirpath, dirnames, filenames : iterator
An iterator over the 3-tuples
dirpath, dirnames, filenames
.dirpath
is a string, the path to the directory.dirnames
is a list of the names of the subdirectories indirpath
(excluding ‘.’ and ‘..’).filenames
is a list of the names of the non-directory files/objects indirpath
.Notes
The names in the lists are just names, with no path components. To get a full path (which begins with top) to a file or directory in
dirpath
, useos.path.join(dirpath, name)
.
-