#include <QDir.h>
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.
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 ®ex=FXString::nullStr(), int sortBy=Name|IgnoreCase, int filter=All) | |
QDir (const QDir &o) | |
QDir & | operator= (const QDir &o) |
QDir & | operator= (const FXString &path) |
bool | operator== (const QDir &o) const |
bool | operator!= (const QDir &o) const |
void | setPath (const FXString &path) |
const FXString & | path () 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 FXString & | nameFilter () const |
void | setNameFilter (const FXString ®ex) |
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 FXString & | operator[] (int idx) const |
QStringList | entryList (const FXString ®ex, int filter=DefaultFilter, int sorting=DefaultSort) |
QStringList | entryList (int filter=DefaultFilter, int sorting=DefaultSort) |
const QFileInfoList * | entryInfoList (const FXString ®ex, int filter=DefaultFilter, int sorting=DefaultSort) |
const QFileInfoList * | entryInfoList (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) |
enum FX::QDir::FilterSpec |
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)
enum FX::QDir::SortSpec |
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
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.
Returns path of file if it were in this directory.
Returns absolute path of file if it were in this directory.
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.
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.
Returns true if the file name matches the specified regular expression.
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