:right-sidebar: True Dir =================================================================== .. currentmodule:: gi.repository.GLib .. class:: Dir(*args, **kwargs) :no-contents-entry: An opaque structure representing an opened directory. Constructors ------------ .. rst-class:: interim-class .. class:: Dir :no-index: .. classmethod:: open(path: str, flags: int) -> ~gi.repository.GLib.Dir Opens a directory for reading. The names of the files in the directory can then be retrieved using :func:`~gi.repository.GLib.Dir.read_name`. Note that the ordering is not defined. :param path: the path to the directory you are interested in. On Unix in the on-disk encoding. On Windows in UTF-8 :param flags: Currently must be set to 0. Reserved for future use. :return: a new file descriptor, or -1 if an error occurred. The return value can be used exactly like the return value from open(). Methods ------- .. rst-class:: interim-class .. class:: Dir :no-index: .. method:: close() -> None Closes the directory immediately and decrements the reference count. Once the reference count reaches zero, the ``GDir`` structure itself will be freed. Prior to GLib 2.80, ``GDir`` was not reference counted. It is an error to call any of the ``GDir`` methods other than :obj:`~gi.repository.GLib.Dir.ref` and :obj:`~gi.repository.GLib.Dir.unref` on a ``GDir`` after calling :obj:`~gi.repository.GLib.Dir.close` on it. :return: :const:`True` on success, :const:`False` if there was an error. .. classmethod:: make_tmp() -> str Creates a subdirectory in the preferred directory for temporary files (as returned by :func:`~gi.repository.GLib.get_tmp_dir`). ``tmpl`` should be a string in the GLib file name encoding containing a sequence of six 'X' characters, as the parameter to :func:`~gi.repository.GLib.mkstemp`. However, unlike these functions, the template should only be a basename, no directory components are allowed. If template is :const:`None`, a default template is used. Note that in contrast to :func:`~gi.repository.GLib.mkdtemp` (and mkdtemp()) ``tmpl`` is not modified, and might thus be a read-only literal string. .. versionadded:: 2.30 .. method:: read_name() -> str Retrieves the name of another entry in the directory, or :const:`None`. The order of entries returned from this function is not defined, and may vary by file system or other operating-system dependent factors. :const:`None` may also be returned in case of errors. On Unix, you can check ``errno`` to find out if :const:`None` was returned because of an error. On Unix, the '.' and '..' entries are omitted, and the returned name is in the on-disk encoding. On Windows, as is true of all GLib functions which operate on filenames, the returned name is in UTF-8. .. method:: rewind() -> None Resets the given directory. The next call to :func:`~gi.repository.GLib.Dir.read_name` will return the first entry again.