A QDir can point to a file using either a relative or an absolute path. Absolute paths begin with the directory separator "/" (optionally preceded by a drive specification under Windows). If you always use "/" as a directory separator, TQt will translate your paths to conform to the underlying operating system. Relative file names begin with a directory name or a file name and specify a path relative to the current directory.
The "current" path refers to the application's working directory. A QDir's own path is set and retrieved with setPath() and path().
.PP
An example of an absolute path is the string "/tmp/quartz", a relative path might look like "src/fatlib". You can use the function isRelative() to check if a QDir is using a relative or an absolute file path. Call convertToAbs() to convert a relative QDir to an absolute one. For a simplified path use cleanDirPath(). To obtain a path which has no symbolic links or redundant ".." elements use canonicalPath(). The path can be set with setPath(), and changed with cd() and cdUp().
.PP
QDir provides several static functions, for example, setCurrent() to set the application's working directory and currentDirPath() to retrieve the application's working directory. Access to some common paths is provided with the static functions, current(), home() and root() which return QDir objects or currentDirPath(), homeDirPath() and rootDirPath() which return the path as a string. If you want to know about your application's path use QApplication::applicationDirPath().
.PP
The number of entries in a directory is returned by count(). Obtain a string list of the names of all the files and directories in a directory with entryList(). If you prefer a list of QFileInfo pointers use entryInfoList(). Both these functions can apply a name filter, an attributes filter (e.g. read-only, files not directories, etc.), and a sort order. The filters and sort may be set with calls to setNameFilter(), setFilter() and setSorting(). They may also be specified in the entryList() and entryInfoList()'s arguments.
.PP
Create a new directory with mkdir(), rename a directory with rename() and remove an existing directory with rmdir(). Remove a file with remove(). You can interrogate a directory with exists(), isReadable() and isRoot().
.PP
To get a path with a filename use filePath(), and to get a directory name use dirName(); neither of these functions checks for the existence of the file or directory.
.PP
The list of root directories is provided by drives(); on Unix systems this returns a list containing one root directory, "/"; on Windows the list will usually contain "C:/", and possibly "D:/", etc.
It is easiest to work with "/" separators in TQt code. If you need to present a path to the user or need a path in a form suitable for a function in the underlying operating system use convertSeparators().
See also QApplication::applicationDirPath() and Input/Output and Networking.
.SS "Member Type Documentation"
.SH "QDir::FilterSpec"
This enum describes the filtering options available to QDir, e.g. for entryList() and entryInfoList(). The filter value is specified by OR-ing together values from the following list:
.TP
\fCQDir::Dirs\fR - List directories only.
.TP
\fCQDir::Files\fR - List files only.
.TP
\fCQDir::Drives\fR - List disk drives (ignored under Unix).
.TP
\fCQDir::NoSymLinks\fR - Do not list symbolic links (ignored by operating systems that don't support symbolic links).
.TP
\fCQDir::All\fR - List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System).
.TP
\fCQDir::TypeMask\fR - A mask for the the Dirs, Files, Drives and NoSymLinks flags.
.TP
\fCQDir::Readable\fR - List files for which the application has read access.
.TP
\fCQDir::Writable\fR - List files for which the application has write access.
.TP
\fCQDir::Executable\fR - List files for which the application has execute access. Executables needs to be combined with Dirs or Files.
.TP
\fCQDir::RWEMask\fR - A mask for the Readable, Writable and Executable flags.
.TP
\fCQDir::Modified\fR - Only list files that have been modified (ignored under Unix).
.TP
\fCQDir::Hidden\fR - List hidden files (on Unix, files starting with a .).
.TP
\fCQDir::System\fR - List system files (on Unix, FIFOs, sockets and device files)
.TP
\fCQDir::AccessMask\fR - A mask for the Readable, Writable, Executable Modified, Hidden and System flags
.TP
\fCQDir::DefaultFilter\fR - Internal flag.
.PP
If you do not set any of Readable, Writable or Executable, QDir will set all three of them. This makes the default easy to write and at the same time useful.
.PP
Examples:
.)l \fCReadable|Writable\fR means list all files for which the
application has read access, write access or both. \fCDirs|Drives\fR means list drives, directories, all files that the application can read, write or execute, and also symlinks to such files/directories.
.SH "QDir::SortSpec"
This enum describes the sort options available to QDir, e.g. for entryList() and entryInfoList(). The sort value is specified by OR-ing together values from the following list:
.TP
\fCQDir::Name\fR - Sort by name.
.TP
\fCQDir::Time\fR - Sort by time (modification time).
.TP
\fCQDir::Size\fR - Sort by file size.
.TP
\fCQDir::Unsorted\fR - Do not sort.
.TP
\fCQDir::SortByMask\fR - A mask for Name, Time and Size.
.TP
\fCQDir::DirsFirst\fR - Put the directories first, then the files.
.TP
\fCQDir::Reversed\fR - Reverse the sort order.
.TP
\fCQDir::IgnoreCase\fR - Sort case-insensitively.
.TP
\fCQDir::LocaleAware\fR - Sort names using locale aware compares
.TP
\fCQDir::DefaultSort\fR - Internal flag.
.PP
You can only specify one of the first four.
.PP
If you specify both DirsFirst and Reversed, directories are still put first, but in reverse order; the files will be listed after the directories, again in reverse order.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QDir::QDir ()"
Constructs a QDir pointing to the current directory (".").
Constructs a QDir with path \fIpath\fR, that filters its entries by name using \fInameFilter\fR and by attributes using \fIfilterSpec\fR. It also sorts the names using \fIsortSpec\fR.
.PP
The default \fInameFilter\fR is an empty string, which excludes nothing; the default \fIfilterSpec\fR is All, which also means exclude nothing. The default \fIsortSpec\fR is \fCName|IgnoreCase\fR, i.e. sort by name case-insensitively.
If \fIpath\fR is "" or TQString::null, QDir uses "." (the current directory). If \fInameFilter\fR is "" or TQString::null, QDir uses the name filter "*" (all files).
Returns the absolute path name of a file in the directory. Does \fInot\fR check if the file actually exists in the directory. Redundant multiple separators or "." and ".." directories in \fIfileName\fR will not be removed (see cleanDirPath()).
.PP
If \fIacceptAbsPath\fR is TRUE a \fIfileName\fR starting with a separator "/" will be returned without change. If \fIacceptAbsPath\fR is FALSE an absolute path will be prepended to the fileName and the resultant string returned.
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.
.PP
See also setPath(), canonicalPath(), exists(), cleanDirPath(), dirName(), and absFilePath().
On systems that do not have symbolic links this function will always return the same string that absPath() returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalPath() returns TQString::null.
If \fIacceptAbsPath\fR is TRUE a path starting with separator "/" will cause the function to change to the absolute directory. If \fIacceptAbsPath\fR is FALSE any number of separators at the beginning of \fIdirName\fR will be removed and the function will descend into \fIdirName\fR.
.PP
Returns TRUE if the new directory exists and is readable; otherwise returns FALSE. Note that the logical cd() operation is not performed if the new directory does not exist.
.PP
Calling cd( ".." ) is equivalent to calling cdUp().
.PP
See also cdUp(), isReadable(), exists(), and path().
.PP
Example: fileiconview/mainwindow.cpp.
.SH "bool QDir::cdUp ()\fC [virtual]\fR"
Changes directory by moving one directory up from the QDir's current directory.
.PP
Returns TRUE if the new directory exists and is readable; otherwise returns FALSE. Note that the logical cdUp() operation is not performed if the new directory does not exist.
.PP
See also cd(), isReadable(), exists(), and path().
Removes all multiple directory separators "/" and resolves any"
."s or ".."s found in the path, \fIfilePath\fR.
.PP
Symbolic links are kept. This function does not return the canonical path, but rather the simplest version of the input. For example, "./local" becomes "local", "local/../bin" becomes" bin" and "/local/usr/../bin" becomes "/local/bin".
Returns the name of the directory; this is \fInot\fR the same as the path, e.g. a directory with the name "mail", might have the path" /var/spool/mail". If the directory has no name (e.g. it is the root directory) TQString::null is returned.
Returns a list of the root directories on this system. On Windows this returns a number of QFileInfo objects containing "C:/", "D:/" etc. On other operating systems, it returns a list containing just one root directory (e.g. "/").
.PP
The returned pointer is owned by Qt. Callers should \fInot\fR delete or modify it.
.PP
Example: dirview/main.cpp.
.SH "QStrList QDir::encodedEntryList ( int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const\fC [virtual]\fR"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
This function is included to easy porting from TQt 1.x to TQt 2.0, it is the same as entryList(), but encodes the filenames as 8-bit strings using QFile::encodedName().
This function is included to easy porting from TQt 1.x to TQt 2.0, it is the same as entryList(), but encodes the filenames as 8-bit strings using QFile::encodedName().
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter().
.PP
The filter and sorting specifications can be overridden using the \fInameFilter\fR, \fIfilterSpec\fR and \fIsortSpec\fR arguments.
.PP
Returns 0 if the directory is unreadable or does not exist.
.PP
The returned pointer is a const pointer to a QFileInfoList. The list is owned by the QDir object and will be reused on the next call to entryInfoList() for the same QDir instance. If you want to keep the entries of the list after a subsequent call to this function you must copy them.
.PP
Note: QFileInfoList is really a QPtrList<QFileInfo>.
.PP
See also entryList(), setNameFilter(), setSorting(), and setFilter().
.PP
Examples:
.)l dirview/dirview.cpp and fileiconview/qfileiconview.cpp.
.SH "const QFileInfoList * QDir::entryInfoList ( int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const\fC [virtual]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter().
.PP
The filter and sorting specifications can be overridden using the \fIfilterSpec\fR and \fIsortSpec\fR arguments.
.PP
Returns 0 if the directory is unreadable or does not exist.
.PP
The returned pointer is a const pointer to a QFileInfoList. The list is owned by the QDir object and will be reused on the next call to entryInfoList() for the same QDir instance. If you want to keep the entries of the list after a subsequent call to this function you must copy them.
.PP
Note: QFileInfoList is really a QPtrList<QFileInfo>.
.PP
See also entryList(), setNameFilter(), setSorting(), and setFilter().
Returns a list of the names of all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter().
.PP
The filter and sorting specifications can be overridden using the \fInameFilter\fR, \fIfilterSpec\fR and \fIsortSpec\fR arguments.
.PP
Returns an empty list if the directory is unreadable or does not exist.
.PP
See also entryInfoList(), setNameFilter(), setSorting(), and setFilter().
.PP
Example: table/statistics/statistics.cpp.
.SH "QStringList QDir::entryList ( int filterSpec = DefaultFilter, int sortSpec = DefaultSort ) const\fC [virtual]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns a list of the names of all the files and directories in the directory, ordered in accordance with setSorting() and filtered in accordance with setFilter() and setNameFilter().
.PP
The filter and sorting specifications can be overridden using the \fIfilterSpec\fR and \fIsortSpec\fR arguments.
.PP
Returns an empty list if the directory is unreadable or does not exist.
.PP
See also entryInfoList(), setNameFilter(), setSorting(), and setFilter().
If \fIacceptAbsPath\fR is TRUE a path starting with separator "/" will check the file with the absolute path. If \fIacceptAbsPath\fR is FALSE any number of separators at the beginning of \fIname\fR will be removed and the resultant file name will be checked.
.PP
Returns TRUE if the file exists; otherwise returns FALSE.
.PP
See also QFileInfo::exists() and QFile::exists().
.SH "bool QDir::exists () const\fC [virtual]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Returns TRUE if the \fIdirectory\fR exists; otherwise returns FALSE. (If a file with the same name is found this function will return FALSE).
Returns the path name of a file in the directory. Does \fInot\fR check if the file actually exists in the directory. If the QDir is relative the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in \fIfileName\fR will not be removed (see cleanDirPath()).
.PP
If \fIacceptAbsPath\fR is TRUE a \fIfileName\fR starting with a separator "/" will be returned without change. If \fIacceptAbsPath\fR is FALSE an absolute path will be prepended to the fileName and the resultant string returned.
.PP
See also absFilePath(), isRelative(), and canonicalPath().
.SH "FilterSpec QDir::filter () const"
Returns the value set by setFilter()
.SH "QDir QDir::home ()\fC [static]\fR"
Returns the home directory.
.PP
Under Windows the \fCHOME\fR environment variable is used. If this does not exist the \fCUSERPROFILE\fR environment variable is used. If that does not exist the path is formed by concatenating the \fCHOMEDRIVE\fR and \fCHOMEPATH\fR environment variables. If they don't exist the rootDirPath() is used (this uses the \fCSystemDrive\fR environment variable). If none of these exist "C:\" is used.
.PP
Under non-Windows operating systems the \fCHOME\fR environment variable is used if it exists, otherwise rootDirPath() is used.
Returns TRUE if the directory path is relative to the current directory and returns FALSE if the path is absolute (e.g. under UNIX a path is relative if it does not start with a "/").
Returns TRUE if the \fIfileName\fR matches the wildcard (glob) pattern \fIfilter\fR; otherwise returns FALSE. The \fIfilter\fR may contain multiple patterns separated by spaces or semicolons.
If \fIacceptAbsPath\fR is TRUE a path starting with a separator ('/') will create the absolute directory; if \fIacceptAbsPath\fR is FALSE any number of separators at the beginning of \fIdirName\fR will be removed.
.PP
Returns TRUE if successful; otherwise returns FALSE.
If \fIacceptAbsPath\fR is TRUE a path starting with separator "/" will remove the file with the absolute path. If \fIacceptAbsPath\fR is FALSE any number of separators at the beginning of \fIfileName\fR will be removed and the resultant file name will be removed.
.PP
Returns TRUE if the file is removed successfully; otherwise returns FALSE.
If \fIacceptAbsPaths\fR is TRUE a path starting with a separator ('/') will rename the file with the absolute path; if \fIacceptAbsPaths\fR is FALSE any number of separators at the beginning of the names will be removed.
.PP
Returns TRUE if successful; otherwise returns FALSE.
.PP
On most file systems, rename() fails only if \fIoldName\fR does not exist or if \fInewName\fR and \fIoldName\fR are not on the same partition. On Windows, rename() will fail if \fInewName\fR already exists. However, there are also other reasons why rename() can fail. For example, on at least one file system rename() fails if \fInewName\fR points to an open file.
If \fIacceptAbsPath\fR is TRUE a path starting with a separator ('/') will remove the absolute directory; if \fIacceptAbsPath\fR is FALSE any number of separators at the beginning of \fIdirName\fR will be removed.
.PP
The directory must be empty for rmdir() to succeed.
.PP
Returns TRUE if successful; otherwise returns FALSE.
You do not need to use this function to build file paths. If you always use "/", TQt will translate your paths to conform to the underlying operating system.
Sets the application's current working directory to \fIpath\fR. Returns TRUE if the directory was successfully changed; otherwise returns FALSE.
.SH "void QDir::setFilter ( int filterSpec )\fC [virtual]\fR"
Sets the filter used by entryList() and entryInfoList() to \fIfilterSpec\fR. The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList(). See QDir::FilterSpec.
If \fIenable\fR is TRUE then all directories are included (e.g. in entryList()), and the nameFilter() is only applied to the files. If \fIenable\fR is FALSE then the nameFilter() is applied to both directories and files.
Sets the name filter used by entryList() and entryInfoList() to \fInameFilter\fR.
.PP
The \fInameFilter\fR is a wildcard (globbing) filter that understands" *" and "?" wildcards. (See QRegExp wildcard matching.) You may specify several filter entries all separated by a single space " " or by a semi-colon" ;".
.PP
For example, if you want entryList() and entryInfoList() to list all files ending with either ".cpp" or ".h", you would use either dir.setNameFilter("*.cpp *.h") or dir.setNameFilter("*.cpp;*.h").
Sets the path of the directory to \fIpath\fR. The path is cleaned of redundant ".", ".." and of multiple separators. No check is made to ensure that a directory with this path exists.
.PP
The path can be either absolute or relative. Absolute paths begin with the directory separator "/" (optionally preceded by a drive specification under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory. An example of an absolute path is the string" /tmp/quartz", a relative path might look like "src/fatlib".
.PP
See also path(), absPath(), exists(), cleanDirPath(), dirName(), absFilePath(), isRelative(), and convertToAbs().
.SH "void QDir::setSorting ( int sortSpec )\fC [virtual]\fR"
Sets the sort order used by entryList() and entryInfoList().
.PP
The \fIsortSpec\fR is specified by OR-ing values from the enum QDir::SortSpec.