Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QDir Class Reference

\inmodule QtCore More...

#include <qdir.h>

+ Collaboration diagram for QDir:

Public Types

enum  Filter {
  Dirs = 0x001 , Files = 0x002 , Drives = 0x004 , NoSymLinks = 0x008 ,
  AllEntries = Dirs | Files | Drives , TypeMask = 0x00f , Readable = 0x010 , Writable = 0x020 ,
  Executable = 0x040 , PermissionMask = 0x070 , Modified = 0x080 , Hidden = 0x100 ,
  System = 0x200 , AccessMask = 0x3F0 , AllDirs = 0x400 , CaseSensitive = 0x800 ,
  NoDot = 0x2000 , NoDotDot = 0x4000 , NoDotAndDotDot = NoDot | NoDotDot , NoFilter = -1
}
 This enum describes the filtering options available to QDir; e.g. More...
 
enum  SortFlag {
  Name = 0x00 , Time = 0x01 , Size = 0x02 , Unsorted = 0x03 ,
  SortByMask = 0x03 , DirsFirst = 0x04 , Reversed = 0x08 , IgnoreCase = 0x10 ,
  DirsLast = 0x20 , LocaleAware = 0x40 , Type = 0x80 , NoSort = -1
}
 This enum describes the sort options available to QDir, e.g. More...
 

Public Member Functions

 QDir (const QDir &)
 Constructs a QDir object that is a copy of the QDir object for directory dir.
 
 QDir (const QString &path=QString())
 Constructs a QDir pointing to the given directory path.
 
 QDir (const QString &path, const QString &nameFilter, SortFlags sort=SortFlags(Name|IgnoreCase), Filters filter=AllEntries)
 Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters.
 
 ~QDir ()
 Destroys the QDir object frees up its resources.
 
QDiroperator= (const QDir &)
 Move-assigns other to this QDir instance.
 
void swap (QDir &other) noexcept
 
void setPath (const QString &path)
 Sets the path of the directory to path.
 
QString path () const
 Returns the path.
 
QString absolutePath () const
 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.
 
QString canonicalPath () const
 Returns the canonical path, i.e.
 
QString dirName () const
 Returns the name of the directory; this is not the same as the path, e.g.
 
QString filePath (const QString &fileName) const
 Returns the path name of a file in the directory.
 
QString absoluteFilePath (const QString &fileName) const
 Returns the absolute path name of a file in the directory.
 
QString relativeFilePath (const QString &fileName) const
 Returns the path to fileName relative to the directory.
 
bool cd (const QString &dirName)
 Changes the QDir's directory to dirName.
 
bool cdUp ()
 Changes directory by moving one directory up from the QDir's current directory.
 
QStringList nameFilters () const
 Returns the string list set by setNameFilters()
 
void setNameFilters (const QStringList &nameFilters)
 Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nameFilters.
 
Filters filter () const
 Returns the value set by setFilter()
 
void setFilter (Filters filter)
 Sets the filter used by entryList() and entryInfoList() to filters.
 
SortFlags sorting () const
 Returns the value set by setSorting()
 
void setSorting (SortFlags sort)
 Sets the sort order used by entryList() and entryInfoList().
 
qsizetype count (QT6_DECL_NEW_OVERLOAD) const
 Returns the total number of directories and files in the directory.
 
bool isEmpty (Filters filters=Filters(AllEntries|NoDotAndDotDot)) const
 Returns whether the directory is empty.
 
QString operator[] (qsizetype) const
 Returns the file name at position pos in the list of file names.
 
QStringList entryList (Filters filters=NoFilter, SortFlags sort=NoSort) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
 
QStringList entryList (const QStringList &nameFilters, Filters filters=NoFilter, SortFlags sort=NoSort) const
 Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
 
QFileInfoList entryInfoList (Filters filters=NoFilter, SortFlags sort=NoSort) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
 
QFileInfoList entryInfoList (const QStringList &nameFilters, Filters filters=NoFilter, SortFlags sort=NoSort) const
 Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().
 
bool mkdir (const QString &dirName) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Creates a sub-directory called dirName with default permissions.
 
bool mkdir (const QString &dirName, QFile::Permissions permissions) const
 Creates a sub-directory called dirName.
 
bool rmdir (const QString &dirName) const
 Removes the directory specified by dirName.
 
bool mkpath (const QString &dirPath) const
 Creates the directory path dirPath.
 
bool rmpath (const QString &dirPath) const
 Removes the directory path dirPath.
 
bool removeRecursively ()
 
bool isReadable () const
 Returns true if the directory is readable and we can open files by name; otherwise returns false.
 
bool exists () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the directory exists; otherwise returns false.
 
bool isRoot () const
 Returns true if the directory is the root directory; otherwise returns false.
 
bool isRelative () const
 Returns true if the directory path is relative; otherwise returns false.
 
bool isAbsolute () const
 Returns true if the directory's path is absolute; otherwise returns false.
 
bool makeAbsolute ()
 Converts the directory path to an absolute path.
 
bool remove (const QString &fileName)
 Removes the file, fileName.
 
bool rename (const QString &oldName, const QString &newName)
 Renames a file or directory from oldName to newName, and returns true if successful; otherwise returns false.
 
bool exists (const QString &name) const
 Returns true if the file called name exists; otherwise returns false.
 
void refresh () const
 Refreshes the directory information.
 

Static Public Member Functions

static void setSearchPaths (const QString &prefix, const QStringList &searchPaths)
 
static void addSearchPath (const QString &prefix, const QString &path)
 
static QStringList searchPaths (const QString &prefix)
 
static QString toNativeSeparators (const QString &pathName)
 
static QString fromNativeSeparators (const QString &pathName)
 
static QStringList nameFiltersFromString (const QString &nameFilter)
 
static bool isRelativePath (const QString &path)
 Returns true if path is relative; returns false if it is absolute.
 
static bool isAbsolutePath (const QString &path)
 Returns true if path is absolute; returns false if it is relative.
 
static QFileInfoList drives ()
 Returns a list of the root directories on this system.
 
static constexpr QChar listSeparator () noexcept
 
static QChar separator ()
 Returns the native directory separator: "/" under Unix and "\\" under Windows.
 
static bool setCurrent (const QString &path)
 Sets the application's current working directory to path.
 
static QDir current ()
 Returns the application's current directory.
 
static QString currentPath ()
 Returns the absolute path of the application's current directory.
 
static QDir home ()
 Returns the user's home directory.
 
static QString homePath ()
 Returns the absolute path of the user's home directory.
 
static QDir root ()
 Returns the root directory.
 
static QString rootPath ()
 Returns the absolute path of the root directory.
 
static QDir temp ()
 Returns the system's temporary directory.
 
static QString tempPath ()
 Returns the absolute canonical path of the system's temporary directory.
 
static QString cleanPath (const QString &path)
 Returns path with directory separators normalized (that is, platform-native separators converted to "/") and redundant ones removed, and "."s and ".."s resolved (as far as possible).
 

Protected Member Functions

 QDir (QDirPrivate &d)
 

Protected Attributes

QSharedDataPointer< QDirPrivated_ptr
 

Friends

class QDirIterator
 
class QDirListing
 
Q_CORE_EXPORT bool comparesEqual (const QDir &lhs, const QDir &rhs)
 

Detailed Description

\inmodule QtCore

The QDir class provides access to directory structures and their contents.

\reentrant

\compares equality

A QDir is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system. It can also be used to access Qt's \l{resource system}.

Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.

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). Relative file names begin with a directory name or a file name and specify a path relative to the current directory.

Examples of absolute paths:

QDir("/home/user/Documents")
QDir("C:/Users")

On Windows, the second example above will be translated to {C:\Users} when used to access files.

Examples of relative paths:

You can use the isRelative() or isAbsolute() functions to check if a QDir is using a relative or an absolute file path. Call makeAbsolute() to convert a relative QDir to an absolute one.

Note
Paths starting with a colon ({:}) are always considered absolute, as they denote a QResource.

Definition at line 19 of file qdir.h.

Member Enumeration Documentation

◆ Filter

This enum describes the filtering options available to QDir; e.g.

for entryList() and entryInfoList(). The filter value is specified by combining values from the following list using the bitwise OR operator:

\value Dirs List directories that match the filters. \value AllDirs List all directories; i.e. don't apply the filters to directory names. \value Files List files. \value Drives List disk drives (ignored under Unix). \value NoSymLinks Do not list symbolic links (ignored by operating systems that don't support symbolic links). \value NoDotAndDotDot Do not list the special entries "." and "..". \value NoDot Do not list the special entry ".". \value NoDotDot Do not list the special entry "..". \value AllEntries List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System). \value Readable List files for which the application has read access. The Readable value needs to be combined with Dirs or Files. \value Writable List files for which the application has write access. The Writable value needs to be combined with Dirs or Files. \value Executable List files for which the application has execute access. The Executable value needs to be combined with Dirs or Files. \value Modified Only list files that have been modified (ignored on Unix). \value Hidden List hidden files (on Unix, files starting with a "."). \value System List system files (on Unix, FIFOs, sockets and device files are included; on Windows, {.lnk} files are included) \value CaseSensitive The filter should be case sensitive.

\omitvalue TypeMask \omitvalue AccessMask \omitvalue PermissionMask \omitvalue NoFilter

Functions that use Filter enum values to filter lists of files and directories will include symbolic links to files and directories unless you set the NoSymLinks value.

A default constructed QDir will not filter out files based on their permissions, so entryList() and entryInfoList() will return all files that are readable, writable, executable, or any combination of the three. This makes the default easy to write, and at the same time useful.

For example, setting the Readable, Writable, and Files flags allows all files to be listed for which the application has read access, write access or both. If the Dirs and Drives flags are also included in this combination then all drives, directories, all files that the application can read, write, or execute, and symlinks to such files/directories can be listed.

To retrieve the permissions for a directory, use the entryInfoList() function to get the associated QFileInfo objects and then use the QFileInfo::permissions() to obtain the permissions and ownership for each file.

Enumerator
Dirs 
Files 
Drives 
NoSymLinks 
AllEntries 
TypeMask 
Readable 
Writable 
Executable 
PermissionMask 
Modified 
Hidden 
System 
AccessMask 
AllDirs 
CaseSensitive 
NoDot 
NoDotDot 
NoDotAndDotDot 
NoFilter 

Definition at line 22 of file qdir.h.

◆ SortFlag

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:

\value Name Sort by name. \value Time Sort by time (modification time). \value Size Sort by file size. \value Type Sort by file type (extension). \value Unsorted Do not sort. \value NoSort Not sorted by default.

\value DirsFirst Put the directories first, then the files. \value DirsLast Put the files first, then the directories. \value Reversed Reverse the sort order. \value IgnoreCase Sort case-insensitively. \value LocaleAware Sort items appropriately using the current locale settings.

\omitvalue SortByMask

You can only specify one of the first four.

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.

Enumerator
Name 
Time 
Size 
Unsorted 
SortByMask 
DirsFirst 
Reversed 
IgnoreCase 
DirsLast 
LocaleAware 
Type 
NoSort 

Definition at line 50 of file qdir.h.

Constructor & Destructor Documentation

◆ QDir() [1/4]

QDir::QDir ( const QDir & dir)

Constructs a QDir object that is a copy of the QDir object for directory dir.

See also
operator=()

Definition at line 608 of file qdir.cpp.

Referenced by removeRecursively().

+ Here is the caller graph for this function:

◆ QDir() [2/4]

QDir::QDir ( const QString & path = QString())

Constructs a QDir pointing to the given directory path.

If path is empty the program's working directory, ("."), is used.

See also
currentPath()

Definition at line 574 of file qdir.cpp.

◆ QDir() [3/4]

QDir::QDir ( const QString & path,
const QString & nameFilter,
SortFlags sort = SortFlags(Name | IgnoreCase),
Filters filters = AllEntries )

Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters.

It also sorts the names using sort.

The default nameFilter is an empty string, which excludes nothing; the default filters is \l AllEntries, which also excludes nothing. The default sort is \l Name | \l IgnoreCase, i.e. sort by name case-insensitively.

If path is an empty string, QDir uses "." (the current directory). If nameFilter is an empty string, QDir uses the name filter "*" (all files).

Note
path need not exist.
See also
exists(), setPath(), setNameFilters(), setFilter(), setSorting()

Definition at line 596 of file qdir.cpp.

◆ ~QDir()

QDir::~QDir ( )

Destroys the QDir object frees up its resources.

This has no effect on the underlying directory in the file system.

Definition at line 617 of file qdir.cpp.

◆ QDir() [4/4]

QDir::QDir ( QDirPrivate & p)
explicitprotected

Definition at line 564 of file qdir.cpp.

Member Function Documentation

◆ absoluteFilePath()

QString QDir::absoluteFilePath ( const QString & fileName) const

Returns the absolute path name of a file in the directory.

Does not check if the file actually exists in the directory; but see exists(). Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()).

See also
relativeFilePath(), filePath(), canonicalPath()

Definition at line 808 of file qdir.cpp.

References d, fileName, QStringView::left(), Q_LIKELY, qUtf8Printable, qWarning, toNativeSeparators(), and treatAsAbsolute().

Referenced by QGeoFileTileCacheOsm::getFromOfflineStorage(), QLoggingRegistry::initializeRules(), makeAbsolute(), and searchExecutable().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ absolutePath()

QString QDir::absolutePath ( ) const

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.

See also
setPath(), canonicalPath(), exists(), cleanPath(), dirName(), absoluteFilePath()

Definition at line 666 of file qdir.cpp.

References QAbstractFileEngine::AbsoluteName, and d.

Referenced by QMovie::QMovie(), deleteMissingFiles(), makeAbsolute(), QFileSystemModelPrivate::node(), quick_test_main_with_setup(), relativeFilePath(), removeRecursively(), scanImports(), QMovie::setFileName(), and QQuickFileDialogImpl::setInitialCurrentFolderAndSelectedFile().

+ Here is the caller graph for this function:

◆ addSearchPath()

void QDir::addSearchPath ( const QString & prefix,
const QString & path )
static
Since
4.3

Adds path to the search path for prefix.

See also
setSearchPaths()
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 1138 of file qdir.cpp.

References lock, and path().

+ Here is the call graph for this function:

◆ canonicalPath()

QString QDir::canonicalPath ( ) const

Returns the canonical path, i.e.

a path without symbolic links or redundant "." or ".." elements.

On systems that do not have symbolic links this function will always return the same string that absolutePath() returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalPath() returns an empty string.

Example:

QString bin = "/local/bin"; // where /local/bin is a symlink to /usr/bin
QDir binDir(bin);
QString canonicalBin = binDir.canonicalPath();
// canonicalBin now equals "/usr/bin"
QString ls = "/local/bin/ls"; // where ls is the executable "ls"
QDir lsDir(ls);
QString canonicalLs = lsDir.canonicalPath();
// canonicalLS now equals "/usr/bin/ls".
See also
path(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath()

Definition at line 691 of file qdir.cpp.

References QAbstractFileEngine::CanonicalName, QFileSystemEngine::canonicalName(), and d.

Referenced by QCoreApplicationPrivate::appendApplicationPathToLibraryPaths(), QFileSystemEngine::tempPath(), QQmlJS::Dom::QQmlDomAstCreator::visit(), and QQmlJS::Dom::QQmlDomAstCreator::visit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cd()

bool QDir::cd ( const QString & dirName)

Changes the QDir's directory to dirName.

Returns true if the new directory exists; otherwise returns false. Note that the logical cd() operation is not performed if the new directory does not exist.

Calling cd("..") is equivalent to calling cdUp().

See also
cdUp(), isReadable(), exists(), path()

Definition at line 983 of file qdir.cpp.

References QFileInfo::absoluteFilePath(), QSharedDataPointer< T >::constData(), d, d_ptr, dir, dirName(), QString::indexOf(), isAbsolutePath(), QString::isEmpty(), ok, and qt_cleanPath().

Referenced by cdUp().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cdUp()

bool QDir::cdUp ( )

Changes directory by moving one directory up from the QDir's current directory.

Returns true if the new directory exists; otherwise returns false. Note that the logical cdUp() operation is not performed if the new directory does not exist.

Note
On Android, this is not supported for content URIs. For more information, see \l {Android: DocumentFile.getParentFile()}{DocumentFile.getParentFile()}.
See also
cd(), isReadable(), exists(), path()

Definition at line 1041 of file qdir.cpp.

References cd(), and QString::fromLatin1().

Referenced by QFileSystemEngine::getLinkTarget(), and quick_test_main_with_setup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanPath()

QString QDir::cleanPath ( const QString & path)
static

Returns path with directory separators normalized (that is, platform-native separators converted to "/") and redundant ones removed, and "."s and ".."s resolved (as far as possible).

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

See also
absolutePath(), canonicalPath()

Definition at line 2397 of file qdir.cpp.

References qt_cleanPath().

Referenced by QTemporaryFileName::QTemporaryFileName(), _q_createLegacyEngine_recursive(), _qt_get_directory(), QFileSystemEngine::absoluteName(), absolutePath(), QUrlModel::addUrls(), QFileSystemEngine::canonicalName(), checkExecutable(), deployQmlImports(), dirsList(), findBinary(), QStandardPaths::findExecutable(), findInPath(), getBinaryDependencies(), QFileSystemEngine::getLinkTarget(), QFileSystemEngine::homePath(), loadModelBlendParticleMesh(), loadModelShapeMesh(), main(), makefileEscape(), parseArguments(), parseEarlyArguments(), parseOtoolLibraryLine(), QWindowsShellItem::path(), QLibraryInfoPrivate::path(), prefixFromAppDirHelper(), qt_resource_fixResourceRoot(), readAndroidDependencyXml(), relativeFilePath(), QFileSystemEngine::removeDirectory(), QDirPrivate::resolveAbsoluteEntry(), resolveDyldPrefix(), QQuickFolderListModelPrivate::resolvePath(), runRcc(), scanImports(), QFileDialog::setDirectory(), QFileSystemModel::setRootPath(), QStandardPaths::standardLocations(), QFileSystemEngine::tempPath(), vcRedistDir(), and QQmlJSImportVisitor::visit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ count()

qsizetype QDir::count ( QT6_DECL_NEW_OVERLOAD ) const

Returns the total number of directories and files in the directory.

Equivalent to entryList().count().

Note
In Qt versions prior to 6.5, this function returned {uint}, not {qsizetype}.
See also
operator[](), entryList()

Definition at line 1322 of file qdir.cpp.

References d.

◆ current()

QDir QDir::current ( )
inlinestatic

Returns the application's current directory.

The directory is constructed using the absolute path of the current directory, ensuring that its path() will be the same as its absolutePath().

See also
currentPath(), setCurrent(), home(), root(), temp()

Definition at line 219 of file qdir.h.

Referenced by _qt_get_directory(), QCoreApplication::applicationFilePath(), combinePath(), copyAndroidTemplate(), copyGradleTemplate(), createProject(), QQuickTableViewPrivate::dumpTable(), handleCompileErrors(), parseOptions(), quick_test_main_with_setup(), and searchExecutable().

+ Here is the caller graph for this function:

◆ currentPath()

QString QDir::currentPath ( )
static

Returns the absolute path of the application's current directory.

The current directory is the last directory set with QDir::setCurrent() or, if that was never called, the directory at which this application was started at by the parent process.

See also
current(), setCurrent(), homePath(), rootPath(), tempPath(), QCoreApplication::applicationDirPath()

Definition at line 2053 of file qdir.cpp.

References QFileSystemEngine::currentPath().

Referenced by QFileDialogArgs::QFileDialogArgs(), QQuickFolderDialog::QQuickFolderDialog(), absolutePath(), QQmlEngine::baseUrl(), buildAndroidProject(), QQuickFolderListModel::componentComplete(), createRcc(), createSymbolicLink(), QQuickFileDialog::currentFolder(), QMediaStorageLocation::defaultDirectory(), QIOSFileDialog::hide(), main(), parseOtoolLibraryLine(), prefixFromAppDirHelper(), Q_TRACE_INSTRUMENT(), QTest::qFindTestData(), qMediaFromUserInput(), QTest::qtest_qParseArgs(), quick_test_main_with_setup(), RCCResourceLibrary::readFiles(), QGstreamerMediaEncoder::record(), resolveDyldPrefix(), runQmlImportScanner(), QQuick3DAmbientSound::setSource(), and QQuick3DSpatialSound::setSource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dirName()

QString QDir::dirName ( ) const

Returns the name of the directory; this is not 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) an empty string is returned.

No check is made to ensure that a directory with this name actually exists; but see exists().

See also
path(), filePath(), absolutePath(), absoluteFilePath()

Definition at line 714 of file qdir.cpp.

References QAbstractFileEngine::BaseName, d, d_ptr, and QDirPrivate::fileEngine.

Referenced by cd(), createProject(), QQuickFileDialogImpl::currentFolderName(), mkdir(), mkdir(), packagePath(), quick_test_main_with_setup(), rmdir(), and wrapInFunction().

+ Here is the caller graph for this function:

◆ drives()

QFileInfoList QDir::drives ( )
static

Returns a list of the root directories on this system.

On Windows this returns a list of QFileInfo objects containing "C:/", "D:/", etc. This does not return drives with ejectable media that are empty. On other operating systems, it returns a list containing just one root directory (i.e. "/").

See also
root(), rootPath()

Definition at line 1986 of file qdir.cpp.

References QFSFileEngine::drives().

+ Here is the call graph for this function:

◆ entryInfoList() [1/2]

QFileInfoList QDir::entryInfoList ( const QStringList & nameFilters,
Filters filters = NoFilter,
SortFlags sort = NoSort ) const

Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().

The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

See also
entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists()

Definition at line 1459 of file qdir.cpp.

References d, QList< T >::emplace_back(), filters, nameFilters(), NoFilter, NoSort, QDirListing, and ret.

+ Here is the call graph for this function:

◆ entryInfoList() [2/2]

QFileInfoList QDir::entryInfoList ( Filters filters = NoFilter,
SortFlags sort = NoSort ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().

The attribute filter and sorting specifications can be overridden using the filters and sort arguments.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

See also
entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists()

Definition at line 1387 of file qdir.cpp.

References d, entryInfoList(), and filters.

Referenced by QBenchmarkValgrindUtils::cleanup(), deployTranslations(), entryInfoList(), findBinary(), findMinGWRuntimePaths(), QQuickControlsTestUtils::forEachControl(), FileInfoThread::getFileInfos(), QBenchmarkValgrindUtils::getNewestFileName(), and vcRedistDir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ entryList() [1/2]

QStringList QDir::entryList ( const QStringList & nameFilters,
Filters filters = NoFilter,
SortFlags sort = NoSort ) const

Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().

The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

See also
entryInfoList(), setNameFilters(), setSorting(), setFilter()

Definition at line 1409 of file qdir.cpp.

References d, QList< T >::emplace_back(), filters, nameFilters(), NoFilter, NoSort, ret, SortByMask, and Unsorted.

+ Here is the call graph for this function:

◆ entryList() [2/2]

QStringList QDir::entryList ( Filters filters = NoFilter,
SortFlags sort = NoSort ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting().

The attribute filter and sorting specifications can be overridden using the filters and sort arguments.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

Note
To list symlinks that point to non existing files, \l System must be passed to the filter.
See also
entryInfoList(), setNameFilters(), setSorting(), setFilter()

Definition at line 1364 of file qdir.cpp.

References d, entryList(), and filters.

Referenced by allFilesInside(), codesignBundle(), deployPlugins(), entryList(), QGeoFileTileCacheOsm::getFromOfflineStorage(), printLogcatCrashBuffer(), recursiveCopy(), and recursiveCopyAndDeploy().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exists() [1/2]

bool QDir::exists ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the directory exists; otherwise returns false.

(If a file with the same name is found this function will return false).

The overload of this function that accepts an argument is used to test for the presence of files and directories within a directory.

See also
QFileInfo::exists(), QFile::exists()

Definition at line 1714 of file qdir.cpp.

References d_ptr, and QDirPrivate::exists().

Referenced by QGeoFileTileCacheOsm::QGeoFileTileCacheOsm(), QQmlTypeLoader::absoluteFilePath(), createRcc(), QQmlTypeLoader::directoryExists(), existsAsSpecified(), main(), QSSGQmlUtilities::meshAssetName(), QSSGQmlUtilities::outputTextureAsset(), packagePath(), readInputFile(), recursiveCopy(), scanImports(), and QFileSelectorPrivate::selectionHelper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exists() [2/2]

bool QDir::exists ( const QString & name) const

Returns true if the file called name exists; otherwise returns false.

Unless name contains an absolute file path, the file name is assumed to be relative to the directory itself, so this function is typically used to check for the presence of files within a directory.

See also
QFileInfo::exists(), QFile::exists()

Definition at line 1945 of file qdir.cpp.

References QFileInfo::exists(), filePath(), and qWarning.

+ Here is the call graph for this function:

◆ filePath()

QString QDir::filePath ( const QString & fileName) const

Returns the path name of a file in the directory.

Does not check if the file actually exists in the directory; but see exists(). If the QDir is relative the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()).

See also
dirName(), absoluteFilePath(), isRelative(), canonicalPath()

Definition at line 777 of file qdir.cpp.

References d, fileName, QStringView::left(), ret, and treatAsAbsolute().

Referenced by allFilesInside(), exists(), mkdir(), mkdir(), mkpath(), remove(), removeRecursively(), rename(), rmdir(), rmpath(), and QFileInfo::setFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filter()

QDir::Filters QDir::filter ( ) const

Returns the value set by setFilter()

Definition at line 1170 of file qdir.cpp.

References d.

◆ fromNativeSeparators()

QString QDir::fromNativeSeparators ( const QString & pathName)
static
Since
4.2

Returns pathName using '/' as file separator. On Windows, for instance, fromNativeSeparators("\c{c:\\winnt\\system32}") returns "c:/winnt/system32".

The returned string may be the same as the argument on some operating systems, for example on Unix.

See also
toNativeSeparators(), separator()

Definition at line 961 of file qdir.cpp.

Referenced by QTemporaryFileName::QTemporaryFileName(), QZipWriter::addDirectory(), QZipWriter::addFile(), QZipWriter::addFile(), QZipWriter::addSymLink(), buildAndroidProject(), convertCharArray(), copyQtFiles(), QQuickFolderBreadcrumbBarPrivate::crumbPathsForFolder(), QFileSystemModelPrivate::filePath(), QZipPrivate::fillFileInfo(), QSslCertificate::fromPath(), QFileSystemModelPrivate::name(), Recognizer::nextToken(), QFileSystemModelPrivate::node(), QLibraryInfoPrivate::path(), qt_cleanPath(), readInputFile(), QDirPrivate::setPath(), and QFileSystemModel::setRootPath().

+ Here is the caller graph for this function:

◆ home()

QDir QDir::home ( )
inlinestatic

Returns the user's home directory.

The directory is constructed using the absolute path of the home directory, ensuring that its path() will be the same as its absolutePath().

See homePath() for details.

See also
drives(), current(), root(), temp()

Definition at line 222 of file qdir.h.

Referenced by checkForDrmPermission().

+ Here is the caller graph for this function:

◆ homePath()

QString QDir::homePath ( )
static

Returns the absolute path of the user's home directory.

Under Windows this function will return the directory of the current user's profile. Typically, this is:

Use the toNativeSeparators() function to convert the separators to the ones that are appropriate for the underlying operating system.

If the directory of the current user's profile does not exist or cannot be retrieved, the following alternatives will be checked (in the given order) until an existing and available path is found:

\list 1

  • The path specified by the USERPROFILE environment variable.
  • The path formed by concatenating the HOMEDRIVE and HOMEPATH environment variables.
  • The path specified by the HOME environment variable.
  • The path returned by the rootPath() function (which uses the SystemDrive environment variable)
  • The {C:/} directory. \endlist

Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath().

See also
home(), currentPath(), rootPath(), tempPath()

Definition at line 2102 of file qdir.cpp.

References QFileSystemEngine::homePath().

Referenced by baseWritableLocation(), QFileDialogPrivate::createWidgets(), QMediaStorageLocation::defaultDirectory(), QMacSettingsPrivate::fileName(), QFileDialogPrivate::goHome(), make_user_path_without_qstandard_paths(), startQtAndroidPlugin(), wrapInFunction(), and QGenericUnixTheme::xdgIconThemePaths().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAbsolute()

bool QDir::isAbsolute ( ) const
inline

Returns true if the directory's path is absolute; otherwise returns false.

See isAbsolutePath().

Note
Paths starting with a colon ({:}) are always considered absolute, as they denote a QResource.
See also
isRelative(), makeAbsolute(), cleanPath()

Definition at line 186 of file qdir.h.

References isRelative().

+ Here is the call graph for this function:

◆ isAbsolutePath()

bool QDir::isAbsolutePath ( const QString & path)
inlinestatic

Returns true if path is absolute; returns false if it is relative.

Note
Paths starting with a colon ({:}) are always considered absolute, as they denote a QResource.
See also
isAbsolute(), isRelativePath(), makeAbsolute(), cleanPath(), QResource

Definition at line 184 of file qdir.h.

Referenced by QQmlComponent::QQmlComponent(), addFontToDatabase(), cd(), QGuiApplicationPrivate::createPlatformIntegration(), QIcon::fromTheme(), QUrl::fromUserInput(), QQmlComponentPrivate::loadUrl(), parseOtoolLibraryLine(), and resolveDyldPrefix().

+ Here is the caller graph for this function:

◆ isEmpty()

bool QDir::isEmpty ( Filters filters = Filters(AllEntries | NoDotAndDotDot)) const

Returns whether the directory is empty.

Equivalent to {count() == 0} with filters {QDir::AllEntries | QDir::NoDotAndDotDot}, but faster as it just checks whether the directory contains at least one entry.

Note
Unless you set the filters flags to include {QDir::NoDotAndDotDot} (as the default value does), no directory is empty.
See also
count(), entryList(), setFilter()
Since
5.9

Definition at line 1968 of file qdir.cpp.

References d, and filters.

Referenced by QFileDialog::setDirectory().

+ Here is the caller graph for this function:

◆ isReadable()

bool QDir::isReadable ( ) const

Returns true if the directory is readable and we can open files by name; otherwise returns false.

Warning
A false value from this function is not a guarantee that files in the directory are not accessible.
See also
QFileInfo::isReadable()

Definition at line 1682 of file qdir.cpp.

References d, QAbstractFileEngine::DirectoryType, QFileSystemEngine::fillMetaData(), info, QAbstractFileEngine::PermsMask, QFileDevice::ReadUser, QAbstractFileEngine::ReadUserPerm, and QFileSystemMetaData::UserReadPermission.

+ Here is the call graph for this function:

◆ isRelative()

bool QDir::isRelative ( ) const

Returns true if the directory path is relative; otherwise returns false.

(Under Unix a path is relative if it does not start with a "/").

Note
Paths starting with a colon ({:}) are always considered absolute, as they denote a QResource.
See also
makeAbsolute(), isAbsolute(), isAbsolutePath(), cleanPath()

Definition at line 1772 of file qdir.cpp.

References d_ptr, QDirPrivate::dirEntry, QDirPrivate::fileEngine, and QFileSystemEntry::isRelative().

+ Here is the call graph for this function:

◆ isRelativePath()

bool QDir::isRelativePath ( const QString & path)
static

Returns true if path is relative; returns false if it is absolute.

Note
Paths starting with a colon ({:}) are always considered absolute, as they denote a QResource.
See also
isRelative(), isAbsolutePath(), makeAbsolute()

Definition at line 2411 of file qdir.cpp.

References QFileInfo::isRelative().

Referenced by getLibraryProjectsInOutputFolder(), QQmlTypeLoader::getQmldir(), QQmlTypeLoader::getScript(), QQmlTypeLoader::getType(), makeAbsolute(), QLibraryInfoPrivate::path(), relativeFilePath(), QFileDialog::selectFile(), and QCocoaFileDialogHelper::selectFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isRoot()

bool QDir::isRoot ( ) const

Returns true if the directory is the root directory; otherwise returns false.

Note
If the directory is a symbolic link to the root directory this function returns false. If you want to test for this use canonicalPath(), e.g.
QDir dir("/tmp/root_link");
dir = dir.canonicalPath();
if (dir.isRoot())
qWarning("It is a root link");
See also
root(), rootPath()

Definition at line 1731 of file qdir.cpp.

References d_ptr, QDirPrivate::dirEntry, QDirPrivate::fileEngine, QAbstractFileEngine::FlagsMask, QFileSystemEntry::isRoot(), and QAbstractFileEngine::RootFlag.

+ Here is the call graph for this function:

◆ listSeparator()

QDir::listSeparator ( )
inlinestaticconstexprnoexcept
Since
5.6

Returns the native path list separator: ':' under Unix and ';' under Windows.

See also
separator()

Definition at line 200 of file qdir.h.

Referenced by QmlLsp::QQmlCodeModel::buildPathsForFileUrl(), QStandardPaths::findExecutable(), QQmlToolingUtils::getAndWarnForInvalidDirsFromEnv(), main(), parseEnvPath(), pythonRoot(), and runMoc().

+ Here is the caller graph for this function:

◆ makeAbsolute()

bool QDir::makeAbsolute ( )

Converts the directory path to an absolute path.

If it is already absolute nothing happens. Returns true if the conversion succeeded; otherwise returns false.

See also
isAbsolute(), isAbsolutePath(), isRelative(), cleanPath()

Definition at line 1787 of file qdir.cpp.

References absoluteFilePath(), QAbstractFileEngine::AbsoluteName, absolutePath(), QSharedDataPointer< T >::constData(), d, d_ptr, dir, and isRelativePath().

+ Here is the call graph for this function:

◆ mkdir() [1/2]

bool QDir::mkdir ( const QString & dirName) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Creates a sub-directory called dirName with default permissions.

On POSIX systems the default is to grant all permissions allowed by umask. On Windows, the new directory inherits its permissions from its parent directory.

Definition at line 1525 of file qdir.cpp.

References QFileSystemEngine::createDirectory(), d, dirName(), filePath(), QString::isEmpty(), and qWarning.

Referenced by QSSGQmlUtilities::meshAssetName(), QSSGQmlUtilities::outputTextureAsset(), and QNetworkDiskCachePrivate::prepareLayout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mkdir() [2/2]

bool QDir::mkdir ( const QString & dirName,
QFile::Permissions permissions ) const

Creates a sub-directory called dirName.

Returns true on success; otherwise returns false.

If the directory already exists when this function is called, it will return false.

The permissions of the created directory are set to {permissions}.

On POSIX systems the permissions are influenced by the value of umask.

On Windows the permissions are emulated using ACLs. These ACLs may be in non-canonical order when the group is granted less permissions than others. Files and directories with such permissions will generate warnings when the Security tab of the Properties dialog is opened. Granting the group all permissions granted to others avoids such warnings.

See also
rmdir()
Since
6.3

Definition at line 1503 of file qdir.cpp.

References QFileSystemEngine::createDirectory(), d, dirName(), filePath(), QString::isEmpty(), and qWarning.

+ Here is the call graph for this function:

◆ mkpath()

bool QDir::mkpath ( const QString & dirPath) const

Creates the directory path dirPath.

The function will create all parent directories necessary to create the directory.

Returns true if successful; otherwise returns false.

If the path already exists when this function is called, it will return true.

See also
rmpath()

Definition at line 1577 of file qdir.cpp.

References QFileSystemEngine::createDirectory(), d, filePath(), QString::isEmpty(), and qWarning.

Referenced by createQtConf(), QNetworkDiskCachePrivate::prepareLayout(), recursiveCopy(), recursiveCopyAndDeploy(), QMediaPlayerPrivate::setMedia(), and dom::DataTransfer::toMimeDataWithFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nameFilters()

QStringList QDir::nameFilters ( ) const

Returns the string list set by setNameFilters()

Definition at line 1049 of file qdir.cpp.

References d.

Referenced by entryInfoList(), entryList(), and setNameFilters().

+ Here is the caller graph for this function:

◆ nameFiltersFromString()

QStringList QDir::nameFiltersFromString ( const QString & nameFilter)
static

Returns a list of name filters from the given nameFilter. (If there is more than one filter, each pair of filters is separated by a space or by a semicolon.)

Definition at line 2440 of file qdir.cpp.

References QDirPrivate::splitFilters().

+ Here is the call graph for this function:

◆ operator=()

QDir & QDir::operator= ( const QDir & dir)

Move-assigns other to this QDir instance.

Makes a copy of the dir object and assigns it to this QDir object.

Since
5.2

Definition at line 1866 of file qdir.cpp.

References d_ptr, and dir.

◆ operator[]()

QString QDir::operator[] ( qsizetype pos) const

Returns the file name at position pos in the list of file names.

Equivalent to entryList().at(index). pos must be a valid index position in the list (i.e., 0 <= pos < count()).

Note
In Qt versions prior to 6.5, pos was an {int}, not {qsizetype}.
See also
count(), entryList()

Definition at line 1338 of file qdir.cpp.

References d, and pos.

◆ path()

QString QDir::path ( ) const

Returns the path.

This may contain symbolic links, but never contains redundant ".", ".." or multiple separators.

The returned path can be either absolute or relative (see setPath()).

See also
setPath(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath(), toNativeSeparators(), makeAbsolute()

Definition at line 652 of file qdir.cpp.

References d.

Referenced by QIconTheme::QIconTheme(), addSearchPath(), QFileSystemEngine::getLinkTarget(), QSSGQmlUtilities::meshAssetName(), QFileSystemModelPrivate::node(), QSSGQmlUtilities::outputTextureAsset(), and removeRecursively().

+ Here is the caller graph for this function:

◆ refresh()

void QDir::refresh ( ) const

Refreshes the directory information.

Definition at line 2419 of file qdir.cpp.

References QDirPrivate::clearCache(), d, and QDirPrivate::IncludingMetaData.

+ Here is the call graph for this function:

◆ relativeFilePath()

QString QDir::relativeFilePath ( const QString & fileName) const

Returns the path to fileName relative to the directory.

QDir dir("/home/bob");
s = dir.relativeFilePath("images/file.jpg"); // s is "images/file.jpg"
s = dir.relativeFilePath("/home/mary/file.txt"); // s is "../mary/file.txt"
See also
absoluteFilePath(), filePath(), canonicalPath()

Definition at line 842 of file qdir.cpp.

References absolutePath(), Qt::CaseInsensitive, QStringView::chop(), cleanPath(), QStringView::compare(), dir, file, fileName, isRelativePath(), QFile::remove(), QString::remove(), Qt::SkipEmptyParts, QString::startsWith(), and QString::tokenize().

Referenced by allFilesInside(), changeInstallName(), deployRPaths(), qRelocateResourceFile(), updateFile(), and writeDependencyFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove()

bool QDir::remove ( const QString & fileName)

Removes the file, fileName.

Returns true if the file is removed successfully; otherwise returns false.

Definition at line 1897 of file qdir.cpp.

References fileName, filePath(), qWarning, and QFile::remove().

+ Here is the call graph for this function:

◆ removeRecursively()

bool QDir::removeRecursively ( )
Since
5.0 Removes the directory, including all its contents.

Returns true if successful, otherwise false.

If a file or directory cannot be removed, removeRecursively() keeps going and attempts to delete as many files and sub-directories as possible, then returns false.

If the directory was already removed, the method returns true (expected result already reached).

Note
This function is meant for removing a small application-internal directory (such as a temporary directory), but not user-visible directories. For user-visible operations, it is rather recommended to report errors more precisely to the user, to offer solutions in case of errors, to show progress during the deletion since it could take several minutes, etc.

Definition at line 1639 of file qdir.cpp.

References QDir(), absolutePath(), AllEntries, d_ptr, QDirPrivate::exists(), filePath(), Hidden, NoDotAndDotDot, ok, path(), QFile::permissions(), QDirListing, QFile::remove(), rmdir(), QFile::setPermissions(), System, and QFileDevice::WriteUser.

Referenced by createRcc(), and QFileSystemModel::remove().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rename()

bool QDir::rename ( const QString & oldName,
const QString & newName )

Renames a file or directory from oldName to newName, and returns true if successful; otherwise returns false.

On most file systems, rename() fails only if oldName does not exist, or if a file with the new name already exists. However, there are also other reasons why rename() can fail. For example, on at least one file system rename() fails if newName points to an open file.

If oldName is a file (not a directory) that can't be renamed right away, Qt will try to copy oldName to newName and remove oldName.

See also
QFile::rename()

Definition at line 1922 of file qdir.cpp.

References QFile::exists(), file, filePath(), qWarning, and QFile::rename().

+ Here is the call graph for this function:

◆ rmdir()

bool QDir::rmdir ( const QString & dirName) const

Removes the directory specified by dirName.

The directory must be empty for rmdir() to succeed.

Returns true if successful; otherwise returns false.

See also
mkdir()

Definition at line 1549 of file qdir.cpp.

References d, dirName(), filePath(), QString::isEmpty(), qWarning, and QFileSystemEngine::removeDirectory().

Referenced by removeRecursively(), and QFileSystemModel::rmdir().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rmpath()

bool QDir::rmpath ( const QString & dirPath) const

Removes the directory path dirPath.

The function will remove all parent directories in dirPath, provided that they are empty. This is the opposite of mkpath(dirPath).

Returns true if successful; otherwise returns false.

See also
mkpath()

Definition at line 1603 of file qdir.cpp.

References d, filePath(), QString::isEmpty(), qWarning, and QFileSystemEngine::removeDirectory().

+ Here is the call graph for this function:

◆ root()

QDir QDir::root ( )
inlinestatic

Returns the root directory.

The directory is constructed using the absolute path of the root directory, ensuring that its path() will be the same as its absolutePath().

See rootPath() for details.

See also
drives(), current(), home(), temp()

Definition at line 224 of file qdir.h.

Referenced by QGeoMappingManagerEngineMapboxGL::QGeoMappingManagerEngineMapboxGL(), QAbstractGeoTileCache::baseCacheDirectory(), ensureWritableDir(), ensureWritableDir(), QZipReader::extractAll(), QGeoFileTileCache::init(), QGeoFileTileCacheOsm::init(), QV4::CompiledData::CompilationUnit::localCacheFilePath(), qt_ensureWritableDir(), SharedImageProvider::requestImage(), and wrapInFunction().

+ Here is the caller graph for this function:

◆ rootPath()

QString QDir::rootPath ( )
static

Returns the absolute path of the root directory.

For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/".

See also
root(), drives(), currentPath(), homePath(), tempPath()

Definition at line 2158 of file qdir.cpp.

References QFileSystemEngine::rootPath().

Referenced by QQmlEngine::baseUrl(), QFileDialog::directory(), QFileSystemModelPrivate::node(), and wrapInFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ searchPaths()

QStringList QDir::searchPaths ( const QString & prefix)
static
Since
4.3

Returns the search paths for prefix.

See also
setSearchPaths(), addSearchPath()

Definition at line 1155 of file qdir.cpp.

References lock.

Referenced by _q_createLegacyEngine_recursive().

+ Here is the caller graph for this function:

◆ separator()

QChar QDir::separator ( )
inlinestatic

Returns the native directory separator: "/" under Unix and "\\" under Windows.

You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators().

See also
listSeparator()

Definition at line 209 of file qdir.h.

Referenced by QConfFileSettingsPrivate::QConfFileSettingsPrivate(), QCompleterPrivate::_q_complete(), QFseventsFileSystemWatcherEngine::addPaths(), QFileDialogPrivate::basename(), QQmlEngine::baseUrl(), QSSGQmlUtilities::copyTextureAsset(), QFileDialogPrivate::createDirectory(), createDirectoryWithParents(), QQmlJSLinter::defaultPluginPath(), QFileSystemModel::dropMimeData(), QZipReader::extractAll(), fileFromPath(), QFileSystemModelPrivate::filePath(), QCompletionEngine::filterHistory(), ResourceIOSystem::getOsSeparator(), AssimpImporter::import(), initDefaultPaths(), QTextDocument::loadResource(), QSSGQmlUtilities::meshAssetName(), QFileSystemModel::mkdir(), QQmlEnginePrivate::offlineStorageDatabaseDirectory(), QQmlEngine::offlineStoragePath(), QSSGQmlUtilities::outputTextureAsset(), parseOptions(), QCompleter::pathFromIndex(), QFseventsFileSystemWatcherEngine::processEvent(), QFileSystemEngine::removeDirectory(), QFseventsFileSystemWatcherEngine::removePaths(), QTextBrowserPrivate::resolveUrl(), runMoc(), QFileSystemModel::setData(), QSettings::setPath(), shellQuote(), QCompleter::splitPath(), JsonOutput::toList(), QFileDialogPrivate::typedFiles(), and QSSGQmlUtilities::writeQmlForAnimation().

+ Here is the caller graph for this function:

◆ setCurrent()

bool QDir::setCurrent ( const QString & path)
static

Sets the application's current working directory to path.

Returns true if the directory was successfully changed; otherwise returns false.

QString absolute = "/local/bin";
QString relative = "local/bin";
QFileInfo absFile(absolute);
QFileInfo relFile(relative);
// absFile and relFile now point to the same file
// absFile now points to "/local/bin",
// while relFile points to "/tmp/local/bin"
See also
current(), currentPath(), home(), root(), temp()

Definition at line 2029 of file qdir.cpp.

References QFileSystemEngine::setCurrentPath().

Referenced by QIOSIntegration::QIOSIntegration(), buildAndroidProject(), createRcc(), createSymbolicLink(), QQmlDataTest::initTestCase(), Q_TRACE_INSTRUMENT(), runProcess(), startQtAndroidPlugin(), and wrapInFunction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFilter()

void QDir::setFilter ( Filters filters)

Sets the filter used by entryList() and entryInfoList() to filters.

The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList(). See \l{QDir::Filter}.

See also
filter(), setNameFilters()

Definition at line 1249 of file qdir.cpp.

References d, filters, and QDirPrivate::KeepMetaData.

◆ setNameFilters()

void QDir::setNameFilters ( const QStringList & nameFilters)

Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nameFilters.

Each name filter is a wildcard (globbing) filter that understands {*} and {?} wildcards. See \l{QRegularExpression::fromWildcard()}.

For example, the following code sets three name filters on a QDir to ensure that only files with extensions typically used for C++ source files are listed:

filters << "*.cpp" << "*.cxx" << "*.cc";
dir.setNameFilters(filters);
See also
nameFilters(), setFilter()

Definition at line 1070 of file qdir.cpp.

References d, QDirPrivate::KeepMetaData, and nameFilters().

Referenced by QTlsPrivate::systemCaCertificates().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setPath()

void QDir::setPath ( const QString & path)

Sets the path of the directory to path.

The path is cleaned of redundant ".", ".." and of multiple separators. No check is made to see whether a directory with this path actually exists; but you can check for yourself using exists().

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

See also
path(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath(), isRelative(), makeAbsolute()
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 637 of file qdir.cpp.

References d_ptr, and QDirPrivate::setPath().

Referenced by QTlsPrivate::systemCaCertificates().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setSearchPaths()

void QDir::setSearchPaths ( const QString & prefix,
const QStringList & searchPaths )
static
Since
4.3

Sets or replaces Qt's search paths for file names with the prefix prefix to searchPaths.

To specify a prefix for a file name, prepend the prefix followed by a single colon (e.g., "images:undo.png", "xmldocs:books.xml"). prefix can only contain letters or numbers (e.g., it cannot contain a colon, nor a slash).

Qt uses this search path to locate files with a known prefix. The search path entries are tested in order, starting with the first entry.

QDir::setSearchPaths("docs", QStringList(":/embeddedDocuments"));
...
QPixmap pixmap("icons:undo.png"); // will look for undo.png in QDir::homePath() + "/images"
QFile file("docs:design.odf"); // will look in the :/embeddedDocuments resource path

File name prefix must be at least 2 characters long to avoid conflicts with Windows drive letters.

Search paths may contain paths to \l{The Qt Resource System}.

Definition at line 1108 of file qdir.cpp.

References ch, lock, and qWarning.

Referenced by wrapInFunction().

+ Here is the caller graph for this function:

◆ setSorting()

void QDir::setSorting ( SortFlags sort)

Sets the sort order used by entryList() and entryInfoList().

The sort is specified by OR-ing values from the enum \l{QDir::SortFlag}.

See also
sorting(), SortFlag

Definition at line 1305 of file qdir.cpp.

References d, and QDirPrivate::KeepMetaData.

◆ sorting()

QDir::SortFlags QDir::sorting ( ) const

Returns the value set by setSorting()

See also
setSorting(), SortFlag

Definition at line 1261 of file qdir.cpp.

References d.

◆ swap()

void QDir::swap ( QDir & other)
inlinenoexcept
Since
5.0

Swaps this QDir instance with other. This function is very fast and never fails.

Definition at line 91 of file qdir.h.

References other().

+ Here is the call graph for this function:

◆ temp()

QDir QDir::temp ( )
inlinestatic

Returns the system's temporary directory.

The directory is constructed using the absolute canonical path of the temporary directory, ensuring that its path() will be the same as its absolutePath().

See tempPath() for details.

See also
drives(), current(), home(), root()

Definition at line 226 of file qdir.h.

◆ tempPath()

QString QDir::tempPath ( )
static

Returns the absolute canonical path of the system's temporary directory.

On Unix/Linux systems this is the path in the TMPDIR environment variable or {/tmp} if TMPDIR is not defined. On Windows this is usually the path in the TEMP or TMP environment variable. The path returned by this method doesn't end with a directory separator unless it is the root directory (of a drive).

See also
temp(), currentPath(), homePath(), rootPath()

Definition at line 2132 of file qdir.cpp.

References QFileSystemEngine::tempPath().

Referenced by QQuickSpriteEngine::assembledImage(), baseWritableLocation(), QTlsPrivate::TlsCryptographOpenSSL::continueHandshake(), QFile::copy(), QMediaStorageLocation::defaultDirectory(), iconTempPath(), QMediaPlayerPrivate::setMedia(), tempFilePattern(), and tempFilePattern().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toNativeSeparators()

QString QDir::toNativeSeparators ( const QString & pathName)
static
Since
4.2

Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.

On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\\winnt\\system32".

The returned string may be the same as the argument on some operating systems, for example on Unix.

See also
fromNativeSeparators(), separator()

Definition at line 928 of file qdir.cpp.

References i.

Referenced by absoluteFilePath(), QFileDialogPrivate::basename(), canonicalPath(), checkWarnMessage(), compilerRunTimeLibs(), QWindowsMimeURI::convertFromMime(), createChangeNotification(), createDirectory(), createSymbolicLink(), deploy(), deployPlugin(), deployTranslations(), deployWebEngineCore(), QWindowsXpNativeFileDialog::existingDirCallback(), QWindowsFileIconEngine::filePixmap(), QCompletionEngine::filterHistory(), findDependentQtLibraries(), findPluginNames(), findSharedLibraries(), getDevice(), handleCompileErrors(), QFileDialog::history(), init_platform(), loadRulesFromFile(), main(), main(), Option::messagePrefix(), msgFileDoesNotExist(), msgFindNextFailed(), QQmlLocalStorage::openDatabaseSync(), operator<<(), parseEarlyArguments(), patchQtCore(), QFileDialogPrivate::pathChanged(), prefixMessage(), QTest::qFindTestData(), qtestFixUrl(), queryQtPaths(), quick_test_main_with_setup(), readGpuFeatures(), QFile::rename(), QFileSystemModel::setData(), QUrlModel::setData(), QFileDialogComboBox::setHistory(), shellExecute(), QWindowsNativeFileDialogBase::shellItem(), QCompleter::splitPath(), JsonOutput::toJson(), JsonOutput::toList(), updateFile(), updateFile(), and vcRedistDir().

Friends And Related Symbol Documentation

◆ comparesEqual

Q_CORE_EXPORT bool comparesEqual ( const QDir & lhs,
const QDir & rhs )
friend

Definition at line 1818 of file qdir.cpp.

◆ QDirIterator

friend class QDirIterator
friend

Definition at line 245 of file qdir.h.

◆ QDirListing

friend class QDirListing
friend

Definition at line 246 of file qdir.h.

Referenced by entryInfoList(), and removeRecursively().

Member Data Documentation

◆ d_ptr

QSharedDataPointer<QDirPrivate> QDir::d_ptr
protected

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