#include <gromacs/utility/include/gromacs/utility/directoryenumerator.h>
Lists files in a directory.
If multiple threads share the same DirectoryEnumerator, they must take responsibility for their mutual synchronization, particularly with regard to calling nextFile().
|
| DirectoryEnumerator (const std::filesystem::path &dirname, bool bThrow=true) |
| Opens a directory for listing. More...
|
|
std::optional
< std::filesystem::path > | nextFile () |
| Gets next file in a directory. More...
|
|
|
static std::vector
< std::filesystem::path > | enumerateFilesWithExtension (const std::filesystem::path &dirname, const std::string &extension, bool bThrow) |
| Convenience function to list files with certain extension from a directory. More...
|
|
gmx::DirectoryEnumerator::DirectoryEnumerator |
( |
const std::filesystem::path & |
dirname, |
|
|
bool |
bThrow = true |
|
) |
| |
|
explicit |
Opens a directory for listing.
- Parameters
-
[in] | dirname | Path to the directory to list. |
[in] | bThrow | Whether failure to open the directory should throw. |
- Exceptions
-
std::bad_alloc | if out of memory. |
FileIOError | if opening the directory fails and bThrow == true |
std::vector< std::filesystem::path > gmx::DirectoryEnumerator::enumerateFilesWithExtension |
( |
const std::filesystem::path & |
dirname, |
|
|
const std::string & |
extension, |
|
|
bool |
bThrow |
|
) |
| |
|
static |
Convenience function to list files with certain extension from a directory.
- Parameters
-
[in] | dirname | Path to the directory to list. |
[in] | extension | List files with the given extension (or suffix in file name). |
[in] | bThrow | Whether failure to open the directory should throw. |
- Returns
- List of files with the given extension in
dirname
.
- Exceptions
-
std::bad_alloc | if out of memory. |
FileIOError | if opening the directory fails and bThrow == true . |
FileIOError | if some other I/O error occurs. |
std::optional< std::filesystem::path > gmx::DirectoryEnumerator::nextFile |
( |
| ) |
|
Gets next file in a directory.
- Returns
- Optional name of next file in directory.
- Exceptions
-
std::bad_alloc | if out of memory. |
FileIOError | if listing the next file fails. |
If all files from the directory have been returned (or there are no files in the directory and this is the first call), the method returns std::nullopt. Otherwise, the return value is the optional filename without path information.
If bThrow
passed to the constructor was false
and the directory was not successfully opened, the first call to this function will return false
.
This method is not thread safe when called on the same object by multiple threads. Such use requires external synchronization.
The documentation for this class was generated from the following files: