Dir#
- class Dir(*args, **kwargs)#
An opaque structure representing an opened directory.
Constructors#
- class Dir
- classmethod open(path: str, flags: int) Dir#
Opens a directory for reading. The names of the files in the directory can then be retrieved using
read_name(). Note that the ordering is not defined.- Parameters:
path – the path to the directory you are interested in. On Unix in the on-disk encoding. On Windows in UTF-8
flags – Currently must be set to 0. Reserved for future use.
- Returns:
a new file descriptor, or -1 if an error occurred. The return value can be used exactly like the return value from open().
Methods#
- class Dir
- close() None#
Closes the directory immediately and decrements the reference count.
Once the reference count reaches zero, the
GDirstructure itself will be freed. Prior to GLib 2.80,GDirwas not reference counted.It is an error to call any of the
GDirmethods other thanrefandunrefon aGDirafter callingcloseon it.- Returns:
Trueon success,Falseif there was an error.
- classmethod make_tmp() str#
Creates a subdirectory in the preferred directory for temporary files (as returned by
get_tmp_dir()).tmplshould be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, as the parameter tomkstemp(). However, unlike these functions, the template should only be a basename, no directory components are allowed. If template isNone, a default template is used.Note that in contrast to
mkdtemp()(and mkdtemp())tmplis not modified, and might thus be a read-only literal string.Added in version 2.30.
- read_name() str#
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.Nonemay also be returned in case of errors. On Unix, you can checkerrnoto find out ifNonewas 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.
- rewind() None#
Resets the given directory. The next call to
read_name()will return the first entry again.