Main Page Widgets glibmm Namespaces Book

# Glib::Dir Class Reference
[File Utilities]

Utility class representing an open directory. More...

List of all members.

## Public Types
typedef DirIterator | iterator
typedef DirIterator | const_iterator
## Public Member Functions
| Dir (const std::string& path)
| Opens a directory for reading.
| ~Dir ()
| Closes the directory and deallocates all related resources.
std::string | read_name ()
| Retrieves the name of the next entry in the directory.
void | rewind ()
| Resets the directory.
void | close ()
| Closes the directory and deallocates all related resources.
DirIterator | begin ()
| Get the begin of an input iterator sequence.
DirIterator | end ()
| Get the end of an input iterator sequence.

## Detailed Description

Utility class representing an open directory.

It's highly recommended to use the iterator interface. With iterators, reading an entire directory into a STL container is really easy:

     Glib::Dir dir (directory_path);
     std::list<std::string> entries (dir.begin(), dir.end());

Note:
  The encoding of the directory entries isn't necessarily UTF-8. Use Glib::filename_to_utf8() if you need to display them.

## Member Typedef Documentation

typedef DirIterator Glib::Dir::iterator

typedef DirIterator Glib::Dir::const_iterator

## Constructor & Destructor Documentation

Glib::Dir::Dir | ( | const std::string & | path | ) | `[explicit]`

Opens a directory for reading.

The names of the files in the directory can then be retrieved using read_name().

Parameters:

  | path | The path to the directory you are interested in.

Exceptions:

  | Glib::FileError |

Glib::Dir::~Dir | ( |  | ) |

Closes the directory and deallocates all related resources.

## Member Function Documentation

std::string Glib::Dir::read_name | ( |  | ) |

Retrieves the name of the next entry in the directory.

The `'.'` and `'..'` entries are omitted.

Returns:
  The entry's name or `""` if there are no more entries.

See also:
  begin(), end()

void Glib::Dir::rewind | ( |  | ) |

Resets the directory.

The next call to read_name() will return the first entry again.

void Glib::Dir::close | ( |  | ) |

Closes the directory and deallocates all related resources.

Note that close() is implicitely called by ~Dir(). Thus you don't need to call close() yourself unless you want to close the directory before the destructor runs.

DirIterator Glib::Dir::begin | ( |  | ) |

Get the begin of an input iterator sequence.

Returns:
  An input iterator pointing to the first directory entry.

DirIterator Glib::Dir::end | ( |  | ) |

Get the end of an input iterator sequence.

Returns:
  An input iterator pointing behind the last directory entry.

The documentation for this class was generated from the following file:

- fileutils.h