GLib.Dir¶
Fields¶
None
Methods¶
class |
|
class |
|
|
|
|
|
|
|
|
|
|
Details¶
- class GLib.Dir¶
An opaque structure representing an opened directory.
- classmethod make_tmp(tmpl)[source]¶
- Parameters:
tmpl (
str
orNone
) – Template for directory name, as in g_mkdtemp(), basename only, orNone
for a default template- Raises:
- Returns:
The actual name used. This string should be freed with
GLib.free
() when not needed any longer and is is in the GLib file name encoding. In case of errors,None
is returned and error will be set.- Return type:
Creates a subdirectory in the preferred directory for temporary files (as returned by
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 g_mkstemp(). However, unlike these functions, the template should only be a basename, no directory components are allowed. If template is
None
, a default template is used.Note that in contrast to g_mkdtemp() (and mkdtemp()) tmpl is not modified, and might thus be a read-only literal string.
New in version 2.30.
- classmethod open(path, flags)[source]¶
- Parameters:
- Raises:
- Returns:
a newly allocated
GLib.Dir
on success,None
on failure. If non-None
, you must free the result withGLib.Dir.close
() when you are finished with it.- Return type:
Opens a directory for reading. The names of the files in the directory can then be retrieved using
GLib.Dir.read_name
(). Note that the ordering is not defined.
- close()[source]¶
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 [method`GLib`.Dir.ref] and [method`GLib`.Dir.unref] on aGDir
after calling [method`GLib`.Dir.close] on it.
- read_name()[source]¶
- Returns:
The entry’s name or
None
if there are no more entries. The return value is owned by GLib and must not be modified or freed.- Return type:
Retrieves the name of another entry in the directory, or
None
. The order of entries returned from this function is not defined, and may vary by file system or other operating-system dependent factors.None
may also be returned in case of errors. On Unix, you can checkerrno
to find out ifNone
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.
- ref()[source]¶
- Returns:
the same pointer as
dir
- Return type:
Increment the reference count of
dir
.New in version 2.80.
- rewind()[source]¶
Resets the given directory. The next call to
GLib.Dir.read_name
() will return the first entry again.
- unref()[source]¶
Decrements the reference count of
dir
.Once the reference count reaches zero, the directory will be closed and all resources associated with it will be freed. If [method`GLib`.Dir.close] is called when the reference count is greater than zero, the directory is closed but the
GDir
structure will not be freed until its reference count reaches zero.It is an error to call any of the
GDir
methods other than [method`GLib`.Dir.ref] and [method`GLib`.Dir.unref] on aGDir
after calling [method`GLib`.Dir.close] on it.New in version 2.80.