#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().
|
static std::vector< std::string > | enumerateFilesWithExtension (const char *dirname, const char *extension, bool bThrow) |
| Convenience function to list files with certain extension from a directory. More...
|
|
gmx::DirectoryEnumerator::DirectoryEnumerator |
( |
const char * |
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 |
gmx::DirectoryEnumerator::DirectoryEnumerator |
( |
const std::string & |
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::string > gmx::DirectoryEnumerator::enumerateFilesWithExtension |
( |
const char * |
dirname, |
|
|
const char * |
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. |
bool gmx::DirectoryEnumerator::nextFile |
( |
std::string * |
filename | ) |
|
Gets next file in a directory.
- Parameters
-
[out] | filename | Name of the next file. |
- Returns
false
if there were no more files.
- 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 false
and filename
is cleared. Otherwise, the return value is true
and the first/next file name is returned in filename
. filename
will not contain any path information, only the name of the file.
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: