wxDir
generated from ../src/mod_io/dir.cpp
wxDir is a portable equivalent of Unix open/read/closedir functions which allow
enumerating of the files in a directory. wxDir can enumerate files as well as directories.
The following example checks if the temp-directory exists,
and when it does, it retrieves all files with ".tmp" as extension.
if ( wxDir.exists("c:\\temp") )
{
files = wxDir.getAllFiles("c:\\temp", "*.tmp");
for(e in files)
wxMessageBox(files[e]);
}
See also wxDirTraverser
Constants
wxDirFlags
| Name | Description |
|---|---|
| FILES | |
| DIRS | |
| HIDDEN | |
| DOTDOT | |
| DEFAULT |
Constants used for filtering files. The default: FILES | DIRS | HIDDEN.
Class Methods
exists
exists(DirName) : Boolean
| Name | Type | Default | Description |
|---|---|---|---|
| DirName | String |
Returns true when the directory exists.
getAllFiles
getAllFiles(DirName,
FileSpec = "",
Flags = wxDir.FILES | wxDir.DIRS | wxDir.HIDDEN) : String Array
| Name | Type | Default | Description |
|---|---|---|---|
| DirName | String | ||
| FileSpec | String | ||
| Flags | Integer | wxDir.FILES | wxDir.DIRS | wxDir.HIDDEN |
This function returns an array of all filenames under directory DirName
Only files matching FileSpec are taken. When an empty spec is given,
all files are given.
Remark: when wxDir.DIRS is specified in Flags then
getAllFiles recurses into subdirectories. So be carefull when using this method
on a root directory.
Constructor
wxDir
wxDir(Directory = null)
| Name | Type | Default | Description |
|---|---|---|---|
| Directory | String | null | The name of the directory. |
Constructs a new wxDir object. When no argument is specified, use open afterwards. When a directory is passed, use isOpened to test for errors.
Properties
| Name | Type | Description |
|---|---|---|
name ![]() |
String | Returns the name of the directory itself. The returned string does not have the trailing path separator (slash or backslash). |
opened ![]() |
Boolean | Returns true when the directory was opened by calling open. |
Methods
getFirst
getFirst(FileSpec = "",
Flags = wxDir.FILES | wxDir.DIRS | wxDir.HIDDEN) : String
| Name | Type | Default | Description |
|---|---|---|---|
| FileSpec | String | ||
| Flags | Integer | wxDir.FILES | wxDir.DIRS | wxDir.HIDDEN |
Starts the enumerating. All files matching FileSpec
(or all files when not specified or empty) and Flags will be
enumerated. Use getNext for the next file.
An empty String is returned when there's no file found.
getNext
getNext() : String
Continues to enumerate files and/or directories which satisfy the criteria specified in getFirst. An empty String is returned when there are no more files.
hasFiles
hasFiles(FileSpec = "") : Boolean
| Name | Type | Default | Description |
|---|---|---|---|
| FileSpec | String |
Returns true if the directory contains any files matching the given FileSpec. When no argument is given, it will look if there are files in the directory.
hasSubDirs
hasSubDirs(DirSpec = "") : Boolean
| Name | Type | Default | Description |
|---|---|---|---|
| DirSpec | String |
Returns true if the directory contains any subdirectories matching the given DirSpec. When no argument is given, it will look if there are any subdirectories in the directory.
open
open(Directory) : Boolean
| Name | Type | Default | Description |
|---|---|---|---|
| Directory | String |
Open directory for enumerating files and subdirectories. Returns true on success, or false on failure.
traverse
traverse(Traverser,
FileSpec = "",
Flags = wxDir.FILES | wxDir.DIRS | wxDir.HIDDEN) : Integer
| Name | Type | Default | Description |
|---|---|---|---|
| Traverser | wxDirTraverser | ||
| FileSpec | String | ||
| Flags | Integer | wxDir.FILES | wxDir.DIRS | wxDir.HIDDEN |
Open directory for enumerating files and subdirectories. Returns true on success, or false on failure. For an example see wxDirTraverser.

© 2002 - 2007 Franky Braem.