FX::QDir Class Reference

#include <QDir.h>

List of all members.


Detailed Description

Provides detailed information about a directory in the file system (Qt compatible).

This class permits you to enumerate the contents of a directory in a very flexible fashion. It works in tandem with FX::QFileInfo to provide the ultimate in both directory enumeration and comparing before & after snapshots of directory contents.

Warning:
The wildcard mechanism used by QDir is not the same as QDir. QDir uses a space-separated set of *.x as a file open dialog would use. As Tn has disposed permanently of file open dialogs, FOX-style wildcards were far more useful to me - sorry!
FOX-style wildcards are as follows: ? matches a single char, * matches many, [...] specifies any one of what's between the square brackets. Ranges work, so [1-4] matches any one of 1,2,3,4. [!1-4] or [^1-4] would be any char not 1,2,3,4. Lists of matchable expressions can be delimited using | or , so *.cpp|*.h,*.cxx means anything with the extensions cpp,h or cxx. Brackets nest expressions, so foo.(a,b,c) matches foo.a, foo.b and foo.c. You can escape any of these special characters with \

You should (like QDir) try to avoid fancy filtering as it's slow - often getting the full list and copying the items you want into a new list based upon a speculative retrieval of QFileInfo's can be faster than running a regular expression match on a subset filter though care has been taken to avoid quadratic behaviour (unlike Qt, which goes real slow on large directories). In particular, setting FilterSpec or SortSpec options which require fetching a QFileInfo for each item can be particularly slow. Note that all expression matches are case insensitive - this can cause too much data to be returned on POSIX, but also means consistent behaviour between Windows and POSIX.

QDir like QDir performs a certain amount of caching - the list of names are cached. If a list of FX::QFileInfo's is requested, the cached list of names are used to generate the list of FX::QFileInfo's - which may mean an incomplete listing. If the directory enumerated has vanished altogether, then a null pointer is returned. The static method extractChanges() is additional functionality over Qt.

Note that as with all TnFOX functionality, if something fails it throws an exception. Thus many of the boolean returns are always true.

Public Types

enum  FilterSpec {
  Dirs, Files, NoSymLinks, All,
  TypeMask, Readable, Writeable, Writable,
  Executable, RWEMask, Hidden, AccessMask,
  DefaultFilter
}
enum  SortSpec {
  Name, Time, Size, Unsorted,
  SortByMask, DirsFirst, Reversed, IgnoreCase,
  DefaultSort
}

Public Member Functions

 QDir ()
 QDir (const FXString &path, const FXString &regex=FXString::nullStr(), int sortBy=Name|IgnoreCase, int filter=All)
 QDir (const QDir &o)
QDiroperator= (const QDir &o)
QDiroperator= (const FXString &path)
bool operator== (const QDir &o) const
bool operator!= (const QDir &o) const
void setPath (const FXString &path)
const FXStringpath () const
FXString absPath () const
FXString canonicalPath () const
FXString dirName () const
FXString filePath (const FXString &file, bool acceptAbs=true) const
FXString absFilePath (const FXString &file, bool acceptAbs=true) const
bool cd (const FXString &name, bool acceptAbs=true)
bool cdUp ()
const FXStringnameFilter () const
void setNameFilter (const FXString &regex)
FilterSpec filter () const
void setFilter (int filter)
SortSpec sorting () const
void setSorting (int sorting)
bool matchAllDirs () const
void setMatchAllDirs (bool matchAll)
FXuint count () const
const FXStringoperator[] (int idx) const
QStringList entryList (const FXString &regex, int filter=DefaultFilter, int sorting=DefaultSort)
QStringList entryList (int filter=DefaultFilter, int sorting=DefaultSort)
const QFileInfoListentryInfoList (const FXString &regex, int filter=DefaultFilter, int sorting=DefaultSort)
const QFileInfoListentryInfoList (int filter=DefaultFilter, int sorting=DefaultSort)
void refresh ()
bool mkdir (const FXString &leaf, bool acceptAbs=true)
bool rmdir (const FXString &leaf, bool acceptAbs=true)
bool remove (const FXString &leaf, bool acceptAbs=true)
bool rename (const FXString &src, const FXString &dest, bool acceptAbs=true)
bool exists (const FXString &leaf, bool acceptAbs=true)
bool isReadable () const
bool exists () const
bool isRoot () const
bool isRelative () const
void convertToAbs ()

Static Public Member Functions

static FXString convertSeparators (const FXString &path)
static QStringList drives ()
static FXString separator ()
static QDir current ()
static QDir home ()
static QDir root ()
static FXString currentDirPath ()
static FXString homeDirPath ()
static FXString rootDirPath ()
static bool match (const FXString &filter, const FXString &filename)
static FXString cleanDirPath (const FXString &path)
static bool isRelativePath (const FXString &path)
static QStringList extractChanges (const QDir &A, const QDir &B)


Member Enumeration Documentation

Combine bitwise to specify what to include in the enumeration. Not setting any of Readable, Writeable nor Executable causes all three to become set (fastest)

Enumerator:
Dirs  Include directories.
Files  Include files.
NoSymLinks  Don't include symbolic links.
All  Include everything except hidden (fastest).
Readable  Include readable items.
Writeable  Include writeable items.
Executable  Include executable items.
Hidden  Include hidden items (fastest).

Combine bitwise to specify how to sort the enumeration.

Enumerator:
Name  By name.
Time  By modification time.
Size  By size.
Unsorted  Unsorted (fastest).
DirsFirst  Directories first.
Reversed  Reversed.
IgnoreCase  Ignore case.


Constructor & Destructor Documentation

FX::QDir::QDir (  ) 

Constructs a new instance.

FX::QDir::QDir ( const FXString path,
const FXString regex = FXString::nullStr(),
int  sortBy = Name|IgnoreCase,
int  filter = All 
)

Constructs a new instance enumerating items matching regular expression regex in the directory path, sorted by sortBy and filtered by filter


Member Function Documentation

bool FX::QDir::operator== ( const QDir o  )  const

Note that if the fileinfo list has not been generated in both, it is not compared.

void FX::QDir::setPath ( const FXString path  ) 

Sets the path being enumerated.

const FXString& FX::QDir::path (  )  const

Returns the path being enumerated.

FXString FX::QDir::absPath (  )  const

Returns the absolute path being enumerated.

FXString FX::QDir::canonicalPath (  )  const

Returns the path being enumerated simplified (links followed and ..'s removed).

FXString FX::QDir::dirName (  )  const

Returns the name of the directory being enumerated.

FXString FX::QDir::filePath ( const FXString file,
bool  acceptAbs = true 
) const

Returns path of file if it were in this directory.

FXString FX::QDir::absFilePath ( const FXString file,
bool  acceptAbs = true 
) const

Returns absolute path of file if it were in this directory.

static FXString FX::QDir::convertSeparators ( const FXString path  )  [static]

Returns the same path but with '\' instead of '/' if running on Windows.

bool FX::QDir::cd ( const FXString name,
bool  acceptAbs = true 
)

Change the directory, returning true if the new location exists.

bool FX::QDir::cdUp (  ) 

Changes the directory up one level, returning true if the new location exists.

const FXString& FX::QDir::nameFilter (  )  const

Returns the regular expression filtering the enumeration.

void FX::QDir::setNameFilter ( const FXString regex  ) 

Sets the regular expression filtering the enumeration.

FilterSpec FX::QDir::filter (  )  const

Returns the filter setting.

void FX::QDir::setFilter ( int  filter  ) 

Sets the filter setting.

SortSpec FX::QDir::sorting (  )  const

Returns the sorting setting.

void FX::QDir::setSorting ( int  sorting  ) 

Sets the sorting setting.

bool FX::QDir::matchAllDirs (  )  const

Returns true if all directories are enumerated irrespective of filter.

void FX::QDir::setMatchAllDirs ( bool  matchAll  ) 

Sets if all directories are enumerated irrespective of filter.

FXuint FX::QDir::count (  )  const

Returns how many items are in the enumeration.

const FXString& FX::QDir::operator[] ( int  idx  )  const

Returns the item at index idx.

QStringList FX::QDir::entryList ( const FXString regex,
int  filter = DefaultFilter,
int  sorting = DefaultSort 
)

Returns a string list containing all the items in the enumeration which match regex, filter and sorting.

QStringList FX::QDir::entryList ( int  filter = DefaultFilter,
int  sorting = DefaultSort 
) [inline]

Returns a string list containing all the items in the enumeration which match filter and sorting.

References FX::FXString::nullStr().

const QFileInfoList* FX::QDir::entryInfoList ( const FXString regex,
int  filter = DefaultFilter,
int  sorting = DefaultSort 
)

Returns a list of all the items in the enumeration like entryList() but as FX::QFileInfo's. Needless to say, this call is not as fast as entryList() and it returns zero if the directory does not exist

static QStringList FX::QDir::drives (  )  [static]

Returns a string list detailing all the drives on the system. Will be '/' for POSIX, 'A:/', 'B:/' etc. for Windows. Note that this call breaks API compatibility with QDir.

void FX::QDir::refresh (  ) 

Refreshes the enumeration.

bool FX::QDir::mkdir ( const FXString leaf,
bool  acceptAbs = true 
)

Creates a directory within this directory.

bool FX::QDir::rmdir ( const FXString leaf,
bool  acceptAbs = true 
)

Deletes a directory within this directory. Can delete a directory tree.

bool FX::QDir::remove ( const FXString leaf,
bool  acceptAbs = true 
)

Deletes a file within this directory.

bool FX::QDir::rename ( const FXString src,
const FXString dest,
bool  acceptAbs = true 
)

Renames a file within this directory. Can handle renaming across filing systems.

bool FX::QDir::exists ( const FXString leaf,
bool  acceptAbs = true 
)

Returns true if leaf is in this directory.

bool FX::QDir::isReadable (  )  const

Returns true if the directory is readable.

bool FX::QDir::exists (  )  const

Returns true if the directory exists.

bool FX::QDir::isRoot (  )  const

Returns true if the directory is the root directory of a drive.

bool FX::QDir::isRelative (  )  const

Returns true if the path is relative.

void FX::QDir::convertToAbs (  ) 

Converts the path to an absolute one.

static FXString FX::QDir::separator (  )  [static]

Returns the directory separator character. Same as PATHSEPSTRING.

static QDir FX::QDir::current (  )  [static]

Returns the current directory for this process.

static QDir FX::QDir::home (  )  [static]

Returns the home directory of the current user.

static QDir FX::QDir::root (  )  [static]

Returns the root directory of the system (on Windows, where WINNT lives).

static FXString FX::QDir::currentDirPath (  )  [static]

Returns the current directory path.

static FXString FX::QDir::homeDirPath (  )  [static]

Returns the home directory path.

static FXString FX::QDir::rootDirPath (  )  [static]

Returns the root directory path.

static bool FX::QDir::match ( const FXString filter,
const FXString filename 
) [static]

Returns true if the file name matches the specified regular expression.

static FXString FX::QDir::cleanDirPath ( const FXString path  )  [static]

Returns the simplified form of the path.

static bool FX::QDir::isRelativePath ( const FXString path  )  [static]

Returns true if the path is relative.

static QStringList FX::QDir::extractChanges ( const QDir A,
const QDir B 
) [static]

Returns a list consisting of those filenames in A and B which are either not of the same name in both or one or more of their characteristics has changed. Needs to run entryInfoList() on both so if the older of the two does not contain cached QFileInfo records, they will have to be reread - which means the characteristics will match


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

(C) 2002-2008 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Jun 13 22:27:38 2008 for TnFOX by doxygen v1.5.6