Struct qt_core::QDir

source ·
#[repr(C)]
pub struct QDir { /* private fields */ }
Expand description

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

C++ class: QDir.

C++ documentation:

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

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 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:/Documents and Settings”)

On Windows, the second example above will be translated to C:\Documents and Settings when used to access files.

Examples of relative paths:

QDir(“images/landscape.png”)

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.

Implementations§

source§

impl QDir

source

pub unsafe fn absolute_file_path( &self, file_name: impl CastInto<Ref<QString>> ) -> CppBox<QString>

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()).

Calls C++ function: QString QDir::absoluteFilePath(const QString& fileName) const.

C++ documentation:

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(), and canonicalPath().

source

pub unsafe fn absolute_path(&self) -> CppBox<QString>

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.

Calls C++ function: QString QDir::absolutePath() const.

C++ documentation:

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(), and absoluteFilePath().

source

pub unsafe fn add_resource_search_path(path: impl CastInto<Ref<QString>>)

Use QDir::addSearchPath() with a prefix instead.

Calls C++ function: static void QDir::addResourceSearchPath(const QString& path).

C++ documentation:

Use QDir::addSearchPath() with a prefix instead.

Adds path to the search paths searched in to find resources that are not specified with an absolute path. The default search path is to search only in the root (:/).

See also The Qt Resource System.

source

pub unsafe fn add_search_path( prefix: impl CastInto<Ref<QString>>, path: impl CastInto<Ref<QString>> )

Adds path to the search path for prefix.

Calls C++ function: static void QDir::addSearchPath(const QString& prefix, const QString& path).

C++ documentation:

Adds path to the search path for prefix.

This function was introduced in Qt 4.3.

See also setSearchPaths().

source

pub unsafe fn canonical_path(&self) -> CppBox<QString>

Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements.

Calls C++ function: QString QDir::canonicalPath() const.

C++ documentation:

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(), and absoluteFilePath().

source

pub unsafe fn cd(&self, dir_name: impl CastInto<Ref<QString>>) -> bool

Changes the QDir's directory to dirName.

Calls C++ function: bool QDir::cd(const QString& dirName).

C++ documentation:

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(), and path().

source

pub unsafe fn cd_up(&self) -> bool

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

Calls C++ function: bool QDir::cdUp().

C++ documentation:

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.

See also cd(), isReadable(), exists(), and path().

source

pub unsafe fn clean_path(path: impl CastInto<Ref<QString>>) -> CppBox<QString>

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

Calls C++ function: static QString QDir::cleanPath(const QString& path).

C++ documentation:

Returns path with directory separators normalized (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() and canonicalPath().

source

pub unsafe fn copy_from_q_dir( &self, arg1: impl CastInto<Ref<QDir>> ) -> Ref<QDir>

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

Calls C++ function: QDir& QDir::operator=(const QDir& arg1).

C++ documentation:

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

source

pub unsafe fn copy_from_q_string( &self, path: impl CastInto<Ref<QString>> ) -> Ref<QDir>

Calls C++ function: QDir& QDir::operator=(const QString& path).

source

pub unsafe fn count(&self) -> c_uint

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

Calls C++ function: unsigned int QDir::count() const.

C++ documentation:

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

Equivalent to entryList().count().

See also operator[]() and entryList().

source

pub unsafe fn current() -> CppBox<QDir>

Returns the application's current directory.

Calls C++ function: static QDir QDir::current().

C++ documentation:

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(), and temp().

source

pub unsafe fn current_path() -> CppBox<QString>

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.

Calls C++ function: static QString QDir::currentPath().

C++ documentation:

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(), and QCoreApplication::applicationDirPath().

source

pub unsafe fn dir_name(&self) -> CppBox<QString>

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.

Calls C++ function: QString QDir::dirName() const.

C++ documentation:

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(), and absoluteFilePath().

source

pub unsafe fn drives() -> CppBox<QListOfQFileInfo>

Returns a list of the root directories on this system.

Calls C++ function: static QList<QFileInfo> QDir::drives().

C++ documentation:

Returns a list of the root directories on this system.

On Windows this returns a list of QFileInfo objects containing "C:/", "D:/", etc. On other operating systems, it returns a list containing just one root directory (i.e. "/").

See also root() and rootPath().

source

pub unsafe fn entry_info_list_q_flags_filter_q_flags_sort_flag( &self, filters: QFlags<Filter>, sort: QFlags<SortFlag> ) -> CppBox<QListOfQFileInfo>

This is an overloaded function.

Calls C++ function: QList<QFileInfo> QDir::entryInfoList(QFlags<QDir::Filter> filters = …, QFlags<QDir::SortFlag> sort = …) const.

C++ documentation:

This is an overloaded function.

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(), and exists().

source

pub unsafe fn entry_info_list_q_string_list_q_flags_filter_q_flags_sort_flag( &self, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter>, sort: QFlags<SortFlag> ) -> CppBox<QListOfQFileInfo>

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().

Calls C++ function: QList<QFileInfo> QDir::entryInfoList(const QStringList& nameFilters, QFlags<QDir::Filter> filters = …, QFlags<QDir::SortFlag> sort = …) const.

C++ documentation:

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(), and exists().

source

pub unsafe fn entry_info_list_q_flags_filter( &self, filters: QFlags<Filter> ) -> CppBox<QListOfQFileInfo>

This is an overloaded function.

Calls C++ function: QList<QFileInfo> QDir::entryInfoList(QFlags<QDir::Filter> filters = …) const.

C++ documentation:

This is an overloaded function.

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(), and exists().

source

pub unsafe fn entry_info_list(&self) -> CppBox<QListOfQFileInfo>

This is an overloaded function.

Calls C++ function: QList<QFileInfo> QDir::entryInfoList() const.

C++ documentation:

This is an overloaded function.

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(), and exists().

source

pub unsafe fn entry_info_list_q_string_list_q_flags_filter( &self, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter> ) -> CppBox<QListOfQFileInfo>

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().

Calls C++ function: QList<QFileInfo> QDir::entryInfoList(const QStringList& nameFilters, QFlags<QDir::Filter> filters = …) const.

C++ documentation:

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(), and exists().

source

pub unsafe fn entry_info_list_q_string_list( &self, name_filters: impl CastInto<Ref<QStringList>> ) -> CppBox<QListOfQFileInfo>

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().

Calls C++ function: QList<QFileInfo> QDir::entryInfoList(const QStringList& nameFilters) const.

C++ documentation:

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(), and exists().

source

pub unsafe fn entry_list_q_flags_filter_q_flags_sort_flag( &self, filters: QFlags<Filter>, sort: QFlags<SortFlag> ) -> CppBox<QStringList>

This is an overloaded function.

Calls C++ function: QStringList QDir::entryList(QFlags<QDir::Filter> filters = …, QFlags<QDir::SortFlag> sort = …) const.

C++ documentation:

This is an overloaded function.

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, System must be passed to the filter.

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

source

pub unsafe fn entry_list_q_string_list_q_flags_filter_q_flags_sort_flag( &self, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter>, sort: QFlags<SortFlag> ) -> CppBox<QStringList>

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().

Calls C++ function: QStringList QDir::entryList(const QStringList& nameFilters, QFlags<QDir::Filter> filters = …, QFlags<QDir::SortFlag> sort = …) const.

C++ documentation:

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(), and setFilter().

source

pub unsafe fn entry_list_q_flags_filter( &self, filters: QFlags<Filter> ) -> CppBox<QStringList>

This is an overloaded function.

Calls C++ function: QStringList QDir::entryList(QFlags<QDir::Filter> filters = …) const.

C++ documentation:

This is an overloaded function.

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, System must be passed to the filter.

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

source

pub unsafe fn entry_list(&self) -> CppBox<QStringList>

This is an overloaded function.

Calls C++ function: QStringList QDir::entryList() const.

C++ documentation:

This is an overloaded function.

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, System must be passed to the filter.

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

source

pub unsafe fn entry_list_q_string_list_q_flags_filter( &self, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter> ) -> CppBox<QStringList>

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().

Calls C++ function: QStringList QDir::entryList(const QStringList& nameFilters, QFlags<QDir::Filter> filters = …) const.

C++ documentation:

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(), and setFilter().

source

pub unsafe fn entry_list_q_string_list( &self, name_filters: impl CastInto<Ref<QStringList>> ) -> CppBox<QStringList>

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().

Calls C++ function: QStringList QDir::entryList(const QStringList& nameFilters) const.

C++ documentation:

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(), and setFilter().

source

pub unsafe fn exists_0a(&self) -> bool

This is an overloaded function.

Calls C++ function: bool QDir::exists() const.

C++ documentation:

This is an overloaded function.

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() and QFile::exists().

source

pub unsafe fn exists_1a(&self, name: impl CastInto<Ref<QString>>) -> bool

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

Calls C++ function: bool QDir::exists(const QString& name) const.

C++ documentation:

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() and QFile::exists().

source

pub unsafe fn file_path( &self, file_name: impl CastInto<Ref<QString>> ) -> CppBox<QString>

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()).

Calls C++ function: QString QDir::filePath(const QString& fileName) const.

C++ documentation:

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(), and canonicalPath().

source

pub unsafe fn filter(&self) -> QFlags<Filter>

Returns the value set by setFilter()

Calls C++ function: QFlags<QDir::Filter> QDir::filter() const.

C++ documentation:

Returns the value set by setFilter()

See also setFilter().

source

pub unsafe fn from_native_separators( path_name: impl CastInto<Ref<QString>> ) -> CppBox<QString>

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

Calls C++ function: static QString QDir::fromNativeSeparators(const QString& pathName).

C++ documentation:

Returns pathName using ‘/’ as file separator. On Windows, for instance, fromNativeSeparators(“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.

This function was introduced in Qt 4.2.

See also toNativeSeparators() and separator().

source

pub unsafe fn home() -> CppBox<QDir>

Returns the user's home directory.

Calls C++ function: static QDir QDir::home().

C++ documentation:

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(), and temp().

source

pub unsafe fn home_path() -> CppBox<QString>

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

Calls C++ function: static QString QDir::homePath().

C++ documentation:

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:

C:/Documents and Settings/Username

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:

  1. The path specified by the USERPROFILE environment variable.
  2. The path formed by concatenating the HOMEDRIVE and HOMEPATH environment variables.
  3. The path specified by the HOME environment variable.
  4. The path returned by the rootPath() function (which uses the SystemDrive environment variable)
  5. The C:/ directory.

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(), and tempPath().

source

pub unsafe fn index(&self, arg1: c_int) -> CppBox<QString>

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()).

Calls C++ function: QString QDir::operator[](int arg1) const.

C++ documentation:

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()).

See also count() and entryList().

source

pub unsafe fn is_absolute(&self) -> bool

Returns true if the directory's path is absolute; otherwise returns false. See isAbsolutePath().

Calls C++ function: bool QDir::isAbsolute() const.

C++ documentation:

Returns true if the directory’s path is absolute; otherwise returns false. See isAbsolutePath().

See also isRelative(), makeAbsolute(), and cleanPath().

source

pub unsafe fn is_absolute_path(path: impl CastInto<Ref<QString>>) -> bool

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

Calls C++ function: static bool QDir::isAbsolutePath(const QString& path).

C++ documentation:

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

See also isAbsolute(), isRelativePath(), makeAbsolute(), and cleanPath().

source

pub unsafe fn is_empty_1a(&self, filters: QFlags<Filter>) -> bool

Returns whether the directory is empty.

Calls C++ function: bool QDir::isEmpty(QFlags<QDir::Filter> filters = …) const.

C++ documentation:

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.

This function was introduced in Qt 5.9.

See also count(), entryList(), and setFilter().

source

pub unsafe fn is_empty_0a(&self) -> bool

Returns whether the directory is empty.

Calls C++ function: bool QDir::isEmpty() const.

C++ documentation:

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.

This function was introduced in Qt 5.9.

See also count(), entryList(), and setFilter().

source

pub unsafe fn is_readable(&self) -> bool

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

Calls C++ function: bool QDir::isReadable() const.

C++ documentation:

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().

source

pub unsafe fn is_relative(&self) -> bool

Returns true if the directory path is relative; otherwise returns false. (Under Unix a path is relative if it does not start with a "/").

Calls C++ function: bool QDir::isRelative() const.

C++ documentation:

Returns true if the directory path is relative; otherwise returns false. (Under Unix a path is relative if it does not start with a “/”).

See also makeAbsolute(), isAbsolute(), isAbsolutePath(), and cleanPath().

source

pub unsafe fn is_relative_path(path: impl CastInto<Ref<QString>>) -> bool

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

Calls C++ function: static bool QDir::isRelativePath(const QString& path).

C++ documentation:

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

See also isRelative(), isAbsolutePath(), and makeAbsolute().

source

pub unsafe fn is_root(&self) -> bool

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

Calls C++ function: bool QDir::isRoot() const.

C++ documentation:

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() and rootPath().

source

pub unsafe fn list_separator() -> CppBox<QChar>

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

Calls C++ function: static QChar QDir::listSeparator().

C++ documentation:

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

This function was introduced in Qt 5.6.

See also separator().

source

pub unsafe fn make_absolute(&self) -> bool

Converts the directory path to an absolute path. If it is already absolute nothing happens. Returns true if the conversion succeeded; otherwise returns false.

Calls C++ function: bool QDir::makeAbsolute().

C++ documentation:

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(), and cleanPath().

source

pub unsafe fn match_q_string_list_q_string( filters: impl CastInto<Ref<QStringList>>, file_name: impl CastInto<Ref<QString>> ) -> bool

This is an overloaded function.

Calls C++ function: static bool QDir::match(const QStringList& filters, const QString& fileName).

C++ documentation:

This is an overloaded function.

Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false. The matching is case insensitive.

See also QRegExp wildcard matching, QRegExp::exactMatch(), entryList(), and entryInfoList().

source

pub unsafe fn match_2_q_string( filter: impl CastInto<Ref<QString>>, file_name: impl CastInto<Ref<QString>> ) -> bool

Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false. The filter may contain multiple patterns separated by spaces or semicolons. The matching is case insensitive.

Calls C++ function: static bool QDir::match(const QString& filter, const QString& fileName).

C++ documentation:

Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false. The filter may contain multiple patterns separated by spaces or semicolons. The matching is case insensitive.

See also QRegExp wildcard matching, QRegExp::exactMatch(), entryList(), and entryInfoList().

source

pub unsafe fn mkdir(&self, dir_name: impl CastInto<Ref<QString>>) -> bool

Creates a sub-directory called dirName.

Calls C++ function: bool QDir::mkdir(const QString& dirName) const.

C++ documentation:

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.

See also rmdir().

source

pub unsafe fn mkpath(&self, dir_path: impl CastInto<Ref<QString>>) -> bool

Creates the directory path dirPath.

Calls C++ function: bool QDir::mkpath(const QString& dirPath) const.

C++ documentation:

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().

source

pub unsafe fn name_filters(&self) -> CppBox<QStringList>

Returns the string list set by setNameFilters()

Calls C++ function: QStringList QDir::nameFilters() const.

C++ documentation:

Returns the string list set by setNameFilters()

See also setNameFilters().

source

pub unsafe fn name_filters_from_string( name_filter: impl CastInto<Ref<QString>> ) -> CppBox<QStringList>

Calls C++ function: static QStringList QDir::nameFiltersFromString(const QString& nameFilter).

source

pub unsafe fn new_1a(path: impl CastInto<Ref<QString>>) -> CppBox<QDir>

Constructs a QDir pointing to the given directory path. If path is empty the program's working directory, ("."), is used.

Calls C++ function: [constructor] void QDir::QDir(const QString& path = …).

C++ documentation:

Constructs a QDir pointing to the given directory path. If path is empty the program’s working directory, (“.”), is used.

See also currentPath().

source

pub unsafe fn new_4a( path: impl CastInto<Ref<QString>>, name_filter: impl CastInto<Ref<QString>>, sort: QFlags<SortFlag>, filter: QFlags<Filter> ) -> CppBox<QDir>

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.

Calls C++ function: [constructor] void QDir::QDir(const QString& path, const QString& nameFilter, QFlags<QDir::SortFlag> sort = …, QFlags<QDir::Filter> filter = …).

C++ documentation:

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 AllEntries, which also means exclude nothing. The default sort is Name | 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 that path need not exist.

See also exists(), setPath(), setNameFilters(), setFilter(), and setSorting().

source

pub unsafe fn new_0a() -> CppBox<QDir>

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

Calls C++ function: [constructor] void QDir::QDir().

C++ documentation:

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

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 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:/Documents and Settings”)

On Windows, the second example above will be translated to C:\Documents and Settings when used to access files.

Examples of relative paths:

QDir(“images/landscape.png”)

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.

source

pub unsafe fn new_3a( path: impl CastInto<Ref<QString>>, name_filter: impl CastInto<Ref<QString>>, sort: QFlags<SortFlag> ) -> CppBox<QDir>

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.

Calls C++ function: [constructor] void QDir::QDir(const QString& path, const QString& nameFilter, QFlags<QDir::SortFlag> sort = …).

C++ documentation:

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 AllEntries, which also means exclude nothing. The default sort is Name | 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 that path need not exist.

See also exists(), setPath(), setNameFilters(), setFilter(), and setSorting().

source

pub unsafe fn new_2a( path: impl CastInto<Ref<QString>>, name_filter: impl CastInto<Ref<QString>> ) -> CppBox<QDir>

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.

Calls C++ function: [constructor] void QDir::QDir(const QString& path, const QString& nameFilter).

C++ documentation:

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 AllEntries, which also means exclude nothing. The default sort is Name | 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 that path need not exist.

See also exists(), setPath(), setNameFilters(), setFilter(), and setSorting().

source

pub unsafe fn new_copy(arg1: impl CastInto<Ref<QDir>>) -> CppBox<QDir>

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

Calls C++ function: [constructor] void QDir::QDir(const QDir& arg1).

C++ documentation:

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

See also operator=().

source

pub unsafe fn path(&self) -> CppBox<QString>

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

Calls C++ function: QString QDir::path() const.

C++ documentation:

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(), and makeAbsolute().

source

pub unsafe fn refresh(&self)

Refreshes the directory information.

Calls C++ function: void QDir::refresh() const.

C++ documentation:

Refreshes the directory information.

source

pub unsafe fn relative_file_path( &self, file_name: impl CastInto<Ref<QString>> ) -> CppBox<QString>

Returns the path to fileName relative to the directory.

Calls C++ function: QString QDir::relativeFilePath(const QString& fileName) const.

C++ documentation:

Returns the path to fileName relative to the directory.


  QDir dir("/home/bob");
  QString s;

  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(), and canonicalPath().

source

pub unsafe fn remove(&self, file_name: impl CastInto<Ref<QString>>) -> bool

Removes the file, fileName.

Calls C++ function: bool QDir::remove(const QString& fileName).

C++ documentation:

Removes the file, fileName.

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

source

pub unsafe fn remove_recursively(&self) -> bool

Removes the directory, including all its contents.

Calls C++ function: bool QDir::removeRecursively().

C++ documentation:

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.

This function was introduced in Qt 5.0.

source

pub unsafe fn rename( &self, old_name: impl CastInto<Ref<QString>>, new_name: impl CastInto<Ref<QString>> ) -> bool

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

Calls C++ function: bool QDir::rename(const QString& oldName, const QString& newName).

C++ documentation:

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().

source

pub unsafe fn rmdir(&self, dir_name: impl CastInto<Ref<QString>>) -> bool

Removes the directory specified by dirName.

Calls C++ function: bool QDir::rmdir(const QString& dirName) const.

C++ documentation:

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().

source

pub unsafe fn rmpath(&self, dir_path: impl CastInto<Ref<QString>>) -> bool

Removes the directory path dirPath.

Calls C++ function: bool QDir::rmpath(const QString& dirPath) const.

C++ documentation:

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().

source

pub unsafe fn root() -> CppBox<QDir>

Returns the root directory.

Calls C++ function: static QDir QDir::root().

C++ documentation:

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(), and temp().

source

pub unsafe fn root_path() -> CppBox<QString>

Returns the absolute path of the root directory.

Calls C++ function: static QString QDir::rootPath().

C++ documentation:

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(), and tempPath().

source

pub unsafe fn search_paths( prefix: impl CastInto<Ref<QString>> ) -> CppBox<QStringList>

Returns the search paths for prefix.

Calls C++ function: static QStringList QDir::searchPaths(const QString& prefix).

C++ documentation:

Returns the search paths for prefix.

This function was introduced in Qt 4.3.

See also setSearchPaths() and addSearchPath().

source

pub unsafe fn separator() -> CppBox<QChar>

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

Calls C++ function: static QChar QDir::separator().

C++ documentation:

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().

source

pub unsafe fn set_current(path: impl CastInto<Ref<QString>>) -> bool

Sets the application's current working directory to path. Returns true if the directory was successfully changed; otherwise returns false.

Calls C++ function: static bool QDir::setCurrent(const QString& path).

C++ documentation:

Sets the application’s current working directory to path. Returns true if the directory was successfully changed; otherwise returns false.

See also current(), currentPath(), home(), root(), and temp().

source

pub unsafe fn set_filter(&self, filter: QFlags<Filter>)

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 QDir::Filter.

Calls C++ function: void QDir::setFilter(QFlags<QDir::Filter> filter).

C++ documentation:

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 QDir::Filter.

See also filter() and setNameFilters().

source

pub unsafe fn set_name_filters( &self, name_filters: impl CastInto<Ref<QStringList>> )

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

Calls C++ function: void QDir::setNameFilters(const QStringList& nameFilters).

C++ documentation:

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 QRegExp wildcard matching.)

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:

QStringList filters; filters << .cpp” << .cxx” << “*.cc”; dir.setNameFilters(filters);

See also nameFilters() and setFilter().

source

pub unsafe fn set_path(&self, path: impl CastInto<Ref<QString>>)

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().

Calls C++ function: void QDir::setPath(const QString& path).

C++ documentation:

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(), and makeAbsolute().

source

pub unsafe fn set_search_paths( prefix: impl CastInto<Ref<QString>>, search_paths: impl CastInto<Ref<QStringList>> )

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

Calls C++ function: static void QDir::setSearchPaths(const QString& prefix, const QStringList& searchPaths).

C++ documentation:

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(“icons”, QStringList(QDir::homePath() + “/images”)); 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 The Qt Resource System.

This function was introduced in Qt 4.3.

See also searchPaths().

source

pub unsafe fn set_sorting(&self, sort: QFlags<SortFlag>)

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

Calls C++ function: void QDir::setSorting(QFlags<QDir::SortFlag> sort).

C++ documentation:

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

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

See also sorting() and SortFlag.

source

pub unsafe fn sorting(&self) -> QFlags<SortFlag>

Returns the value set by setSorting()

Calls C++ function: QFlags<QDir::SortFlag> QDir::sorting() const.

C++ documentation:

Returns the value set by setSorting()

See also setSorting() and SortFlag.

source

pub unsafe fn swap(&self, other: impl CastInto<Ref<QDir>>)

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

Calls C++ function: void QDir::swap(QDir& other).

C++ documentation:

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

This function was introduced in Qt 5.0.

source

pub unsafe fn temp() -> CppBox<QDir>

Returns the system's temporary directory.

Calls C++ function: static QDir QDir::temp().

C++ documentation:

Returns the system’s temporary directory.

The directory is constructed using the absolute 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(), and root().

source

pub unsafe fn temp_path() -> CppBox<QString>

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

Calls C++ function: static QString QDir::tempPath().

C++ documentation:

Returns the absolute 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(), and rootPath().

source

pub unsafe fn to_native_separators( path_name: impl CastInto<Ref<QString>> ) -> CppBox<QString>

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

Calls C++ function: static QString QDir::toNativeSeparators(const QString& pathName).

C++ documentation:

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.

This function was introduced in Qt 4.2.

See also fromNativeSeparators() and separator().

Trait Implementations§

source§

impl CppDeletable for QDir

source§

unsafe fn delete(&self)

Destroys the QDir object frees up its resources. This has no effect on the underlying directory in the file system.

Calls C++ function: [destructor] void QDir::~QDir().

C++ documentation:

Destroys the QDir object frees up its resources. This has no effect on the underlying directory in the file system.

source§

impl PartialEq<Ref<QDir>> for QDir

source§

fn eq(&self, dir: &Ref<QDir>) -> bool

Returns true if directory dir and this directory have the same path and their sort and filter settings are the same; otherwise returns false.

Calls C++ function: bool QDir::operator==(const QDir& dir) const.

C++ documentation:

Returns true if directory dir and this directory have the same path and their sort and filter settings are the same; otherwise returns false.

Example:

// The current directory is “/usr/local” QDir d1(“/usr/local/bin”); QDir d2(“bin”); if (d1 == d2) qDebug(“They’re the same”);

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl RefUnwindSafe for QDir

§

impl Send for QDir

§

impl Sync for QDir

§

impl Unpin for QDir

§

impl UnwindSafe for QDir

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.