1.8 <GDir>

Structure: <GDir>

An opaque structure representing an opened directory.

Procedures

Method: dir:close self
Method: close self

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 dir:ref and dir:unref on a <GDir> after calling dir:close on it.

self

Passed: a <GDir>.

a <GDir>* created by dir:open

Procedure: dir:make-tmp [tmpl] ⇒ %return

Creates a subdirectory in the preferred directory for temporary files (as returned by 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 #f, 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.

tmpl

Passed, or left out: a file name, as a string, or #f.

Template for directory name, as in g_mkdtemp(), basename only, or #f for a default template

%return

Returned: a file name, as a string.

The actual name used. This string should be freed with byte-array:free when not needed any longer and is is in the GLib file name encoding. In case of errors, #f is returned and error will be set.

Procedure: dir:open path flags ⇒ %return

Opens a directory for reading. The names of the files in the directory can then be retrieved using dir:read-name. Note that the ordering is not defined.

path

Passed: a string.

the path to the directory you are interested in. On Unix in the on-disk encoding. On Windows in UTF-8

flags

Passed: an unsigned 32-bit integer.

Currently must be set to 0. Reserved for future use.

%return

Returned: a <GDir>.

a newly allocated <GDir> on success, #f on failure. If non-#f, you must free the result with dir:close when you are finished with it.

Method: dir:read-name self ⇒ %return
Method: read-name self ⇒ %return

Retrieves the name of another entry in the directory, or #f. The order of entries returned from this function is not defined, and may vary by file system or other operating-system dependent factors.

#f may also be returned in case of errors. On Unix, you can check errno to find out if #f 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.

self

Passed: a <GDir>.

a <GDir>* created by dir:open

%return

Returned: a file name, as a string.

The entry’s name or #f if there are no more entries. The return value is owned by GLib and must not be modified or freed.

Method: dir:ref self ⇒ %return
Method: ref self ⇒ %return

Increment the reference count of dir.

self

Passed: a <GDir>.

a <GDir>

%return

Returned: a <GDir>.

the same pointer as dir

Method: dir:rewind self
Method: rewind self

Resets the given directory. The next call to dir:read-name will return the first entry again.

self

Passed: a <GDir>.

a <GDir>* created by dir:open

Method: dir:unref self
Method: unref self

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 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 dir:ref and dir:unref on a <GDir> after calling dir:close on it.

self

Passed: a <GDir>.

a <GDir>