back to io 

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

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 read only String Returns the name of the directory itself. The returned string does not have the trailing path separator (slash or backslash).
opened read only 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.

null 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. null 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

Enumerate all files and directories under the given directory recursively calling the element of the provided wxDirTraverser object for each of them. More precisely, the function will really recurse into subdirectories if flags contains wxDir.DIRS flag. It will ignore the files (but still possibly recurse into subdirectories) if wxDir.FILES flag is given. For each found directory, onDir() is called and onFile() is called for every file. Depending on the return value, the enumeration may continue or stop.

The function returns the total number of files found or -1 on error.



SourceForge.net Logo Support This Project

Table of Contents

Class Methods

exists
getAllFiles

Constructor

wxDir

Properties

name
opened

Methods

getFirst
getNext
hasFiles
hasSubDirs
open
traverse


Design downloaded from Zeroweb.org: Free website templates, layouts, and tools.