![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
#include <qfileinfo.h>
Public Member Functions | |
QFileInfo (QFileInfoPrivate *d) | |
QFileInfo () | |
Constructs an empty QFileInfo object that doesn't refer to any file system entry. | |
QFILEINFO_MAYBE_EXPLICIT | QFileInfo (const QString &file) |
QFILEINFO_MAYBE_EXPLICIT | QFileInfo (const QFileDevice &file) |
Constructs a new QFileInfo that gives information about file file. | |
QFILEINFO_MAYBE_EXPLICIT | QFileInfo (const QDir &dir, const QString &file) |
QFileInfo (const QFileInfo &fileinfo) | |
Constructs a new QFileInfo that is a copy of the given fileinfo. | |
~QFileInfo () | |
Destroys the QFileInfo and frees its resources. | |
QFileInfo & | operator= (const QFileInfo &fileinfo) |
Move-assigns other to this QFileInfo instance. | |
void | swap (QFileInfo &other) noexcept |
void | setFile (const QString &file) |
void | setFile (const QFileDevice &file) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the file that the QFileInfo provides information about to file. | |
void | setFile (const QDir &dir, const QString &file) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the path of the file system entry that this QFileInfo provides information about to path in directory dir. | |
bool | exists () const |
Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false . | |
void | refresh () |
Refreshes the information about the file system entry this QFileInfo refers to, that is, reads in information from the file system the next time a cached property is fetched. | |
QString | filePath () const |
Returns the path of the file system entry this QFileInfo refers to; the path may be absolute or relative. | |
QString | absoluteFilePath () const |
QString | canonicalFilePath () const |
Returns the file system entry's canonical path, including the entry's name, that is, an absolute path without symbolic links or redundant {'.'} or {'..'} elements. | |
QString | fileName () const |
QString | baseName () const |
Returns the base name of the file without the path. | |
QString | completeBaseName () const |
Returns the complete base name of the file without the path. | |
QString | suffix () const |
Returns the suffix (extension) of the file. | |
QString | bundleName () const |
QString | completeSuffix () const |
Returns the complete suffix (extension) of the file. | |
QString | path () const |
Returns the path of the file system entry this QFileInfo refers to, excluding the entry's name. | |
QString | absolutePath () const |
Returns the absolute path of the file system entry this QFileInfo refers to, excluding the entry's name. | |
QString | canonicalPath () const |
Returns the file system entry's canonical path (excluding the entry's name), i.e. | |
QDir | dir () const |
Returns a QDir object representing the path of the parent directory of the file system entry that this QFileInfo refers to. | |
QDir | absoluteDir () const |
Returns a QDir object representing the absolute path of the parent directory of the file system entry that this QFileInfo refers to. | |
bool | isReadable () const |
Returns true if the user can read the file system entry this QFileInfo refers to; otherwise returns false . | |
bool | isWritable () const |
Returns true if the user can write to the file system entry this QFileInfo refers to; otherwise returns false . | |
bool | isExecutable () const |
bool | isHidden () const |
Returns true if the file system entry this QFileInfo refers to is ‘hidden’; otherwise returns false . | |
bool | isNativePath () const |
bool | isRelative () const |
Returns true if the file system entry's path is relative, otherwise returns false (that is, the path is absolute). | |
bool | isAbsolute () const |
Returns true if the file system entry's path is absolute, otherwise returns false (that is, the path is relative). | |
bool | makeAbsolute () |
If the file system entry's path is relative, this method converts it to an absolute path and returns true ; if the path is already absolute, this method returns false . | |
bool | isFile () const |
Returns true if this object points to a file or to a symbolic link to a file. | |
bool | isDir () const |
Returns true if this object points to a directory or to a symbolic link to a directory. | |
bool | isSymLink () const |
bool | isSymbolicLink () const |
Returns true if this object points to a symbolic link; otherwise returns false . | |
bool | isOther () const |
bool | isShortcut () const |
Returns true if this object points to a shortcut; otherwise returns false . | |
bool | isAlias () const |
Returns true if this object points to an alias; otherwise returns false . | |
bool | isJunction () const |
bool | isRoot () const |
Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false . | |
bool | isBundle () const |
QString | symLinkTarget () const |
QString | readSymLink () const |
QString | junctionTarget () const |
QString | owner () const |
Returns the owner of the file. | |
uint | ownerId () const |
Returns the id of the owner of the file. | |
QString | group () const |
Returns the group of the file. | |
uint | groupId () const |
Returns the id of the group the file belongs to. | |
bool | permission (QFile::Permissions permissions) const |
Tests for file permissions. | |
QFile::Permissions | permissions () const |
Returns the complete OR-ed together combination of QFile::Permissions for the file. | |
qint64 | size () const |
Returns the file size in bytes. | |
QDateTime | birthTime () const |
Returns the date and time when the file was created (born), in local time. | |
QDateTime | metadataChangeTime () const |
Returns the date and time when the file's metadata was last changed, in local time. | |
QDateTime | lastModified () const |
Returns the date and time when the file was last modified. | |
QDateTime | lastRead () const |
Returns the date and time when the file was last read (accessed). | |
QDateTime | fileTime (QFile::FileTime time) const |
QDateTime | birthTime (const QTimeZone &tz) const |
Returns the date and time when the file was created (born). | |
QDateTime | metadataChangeTime (const QTimeZone &tz) const |
Returns the date and time when the file's metadata was last changed. | |
QDateTime | lastModified (const QTimeZone &tz) const |
Returns the date and time when the file was last modified. | |
QDateTime | lastRead (const QTimeZone &tz) const |
Returns the date and time when the file was last read (accessed). | |
QDateTime | fileTime (QFile::FileTime time, const QTimeZone &tz) const |
bool | caching () const |
Returns true if caching is enabled; otherwise returns false . | |
void | setCaching (bool on) |
If enable is true, enables caching of file information. | |
void | stat () |
Reads all attributes from the file system. | |
Static Public Member Functions | |
static bool | exists (const QString &file) |
Protected Attributes | |
QSharedDataPointer< QFileInfoPrivate > | d_ptr |
Friends | |
class | QDirIteratorPrivate |
class | QDirListingPrivate |
class | QFileInfoPrivate |
Q_CORE_EXPORT bool | comparesEqual (const QFileInfo &lhs, const QFileInfo &rhs) |
Related Symbols | |
(Note that these are not member symbols.) | |
QFileInfoList | |
Synonym for QList<QFileInfo>. | |
Definition at line 22 of file qfileinfo.h.
|
explicit |
Definition at line 346 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | ) |
Constructs an empty QFileInfo object that doesn't refer to any file system entry.
Definition at line 356 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | const QString & | path | ) |
Constructs a QFileInfo that gives information about a file system entry located at \a path that can be absolute or relative.
! [preserve-relative-path] If path is relative, the QFileInfo will also have a relative path. ! [preserve-relative-path]
\sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath()
Definition at line 370 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | const QFileDevice & | file | ) |
Constructs a new QFileInfo that gives information about file file.
If the file has a relative path, the QFileInfo will also have a relative path.
Definition at line 383 of file qfileinfo.cpp.
Constructs a new QFileInfo that gives information about the given file system entry \a path that is relative to the directory \a dir.
! [preserve-relative-or-absolute] If dir has a relative path, the QFileInfo will also have a relative path.
If path is absolute, then the directory specified by dir will be disregarded. ! [preserve-relative-or-absolute]
\sa isRelative()
Definition at line 401 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | const QFileInfo & | fileinfo | ) |
Constructs a new QFileInfo that is a copy of the given fileinfo.
Definition at line 409 of file qfileinfo.cpp.
QFileInfo::~QFileInfo | ( | ) |
Destroys the QFileInfo and frees its resources.
Definition at line 419 of file qfileinfo.cpp.
QDir QFileInfo::absoluteDir | ( | ) | const |
Returns a QDir object representing the absolute path of the parent directory of the file system entry that this QFileInfo refers to.
Definition at line 952 of file qfileinfo.cpp.
QString QFileInfo::absoluteFilePath | ( | ) | const |
Returns the absolute full path to the file system entry this QFileInfo refers to, including the entry's name. \include qfileinfo.cpp absolute-path-unix-windows
! [windows-network-shares] On Windows, the paths of network shares that are not mapped to a drive letter begin with {//sharename/}. ! [windows-network-shares]
QFileInfo will uppercase drive letters. Note that QDir does not do this. The code snippet below shows this. \snippet code/src_corelib_io_qfileinfo.cpp newstuff This function returns the same as filePath(), unless isRelative() is true. In contrast to canonicalFilePath(), symbolic links or redundant "." or ".." elements are not necessarily removed. \warning If filePath() is empty the behavior of this function is undefined. \sa filePath(), canonicalFilePath(), isRelative()
Definition at line 580 of file qfileinfo.cpp.
QString QFileInfo::absolutePath | ( | ) | const |
Returns the absolute path of the file system entry this QFileInfo refers to, excluding the entry's name.
absolute-path-unix-windows
windows-network-shares
In contrast to canonicalPath() symbolic links or redundant "." or ".." elements are not necessarily removed.
Definition at line 623 of file qfileinfo.cpp.
QString QFileInfo::baseName | ( | ) | const |
Returns the base name of the file without the path.
The base name consists of all characters in the file up to (but not including) the first '.' character.
Example:
The base name of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").
Definition at line 844 of file qfileinfo.cpp.
|
inline |
Returns the date and time when the file was created (born), in local time.
If the file birth time is not available, this function returns an invalid QDateTime.
info-about-target-not-symlink
This function overloads QFileInfo::birthTime(const QTimeZone &tz), and returns the same as {birthTime(QTimeZone::LocalTime)}.
Definition at line 160 of file qfileinfo.h.
Returns the date and time when the file was created (born).
file-times-in-time-zone
If the file birth time is not available, this function returns an invalid QDateTime.
info-about-target-not-symlink
Definition at line 166 of file qfileinfo.h.
QString QFileInfo::bundleName | ( | ) | const |
On \macos and iOS this returns the proper localized name for a bundle if the path isBundle(). On all other platforms an empty QString is returned.
Example:
Definition at line 820 of file qfileinfo.cpp.
bool QFileInfo::caching | ( | ) | const |
Returns true
if caching is enabled; otherwise returns false
.
Definition at line 1758 of file qfileinfo.cpp.
QString QFileInfo::canonicalFilePath | ( | ) | const |
Returns the file system entry's canonical path, including the entry's name, that is, an absolute path without symbolic links or redundant {'.'} or
{'..'} elements.
If the entry does not exist, canonicalFilePath() returns an empty string.
Definition at line 598 of file qfileinfo.cpp.
QString QFileInfo::canonicalPath | ( | ) | const |
Returns the file system entry's canonical path (excluding the entry's name), i.e.
an absolute path without symbolic links or redundant "." or ".." elements.
If the entry does not exist, this method returns an empty string.
Definition at line 640 of file qfileinfo.cpp.
QString QFileInfo::completeBaseName | ( | ) | const |
Returns the complete base name of the file without the path.
The complete base name consists of all characters in the file up to (but not including) the last '.' character.
Example:
Definition at line 865 of file qfileinfo.cpp.
QString QFileInfo::completeSuffix | ( | ) | const |
Returns the complete suffix (extension) of the file.
The complete suffix consists of all characters in the file after (but not including) the first '.'.
Example:
Definition at line 887 of file qfileinfo.cpp.
QDir QFileInfo::dir | ( | ) | const |
Returns a QDir object representing the path of the parent directory of the file system entry that this QFileInfo refers to.
For each of the following, dir() returns the QDir {"~/examples/191697"}.
For each of the following, dir() returns the QDir {"."}.
Definition at line 938 of file qfileinfo.cpp.
bool QFileInfo::exists | ( | ) | const |
Returns true
if the file system entry this QFileInfo refers to exists; otherwise returns false
.
false
. Definition at line 720 of file qfileinfo.cpp.
|
static |
Returns true
if the file system entry path exists; otherwise returns false
.
false
.QFileInfo(path)
.exists() for file system access. Definition at line 745 of file qfileinfo.cpp.
QString QFileInfo::fileName | ( | ) | const |
Returns the name of the file system entry this QFileInfo refers to, excluding the path. Example: \snippet code/src_corelib_io_qfileinfo.cpp 3
! [path-ends-with-slash-empty-name-component]
{'/'}, the entry's name part is considered empty. ! [path-ends-with-slash-empty-name-component] \sa isRelative(), filePath(), baseName(), suffix()
Definition at line 798 of file qfileinfo.cpp.
QString QFileInfo::filePath | ( | ) | const |
Returns the path of the file system entry this QFileInfo refers to; the path may be absolute or relative.
Definition at line 776 of file qfileinfo.cpp.
QDateTime QFileInfo::fileTime | ( | QFile::FileTime | time | ) | const |
QDateTime QFileInfo::fileTime | ( | QFile::FileTime | time, |
const QTimeZone & | tz ) const |
Returns the file time specified by \a time.
! [file-times-in-time-zone] The returned time is in the time zone specified by tz. For example, you can use QTimeZone::LocalTime or QTimeZone::UTC to get the time in the Local time zone or UTC, respectively. Since native file system API typically uses UTC, using QTimeZone::UTC is often faster, as it does not require any conversions. ! [file-times-in-time-zone]
If the time cannot be determined, an invalid date time is returned. \include qfileinfo.cpp info-about-target-not-symlink \since 6.6 \sa birthTime(const QTimeZone &), lastModified(const QTimeZone &), lastRead(const QTimeZone &), metadataChangeTime(const QTimeZone &), QDateTime::isValid()
Definition at line 1719 of file qfileinfo.cpp.
QString QFileInfo::group | ( | ) | const |
Returns the group of the file.
On Windows, on systems where files do not have groups, or if an error occurs, an empty string is returned.
This function can be time consuming under Unix (in the order of milliseconds).
info-about-target-not-symlink
Definition at line 1443 of file qfileinfo.cpp.
uint QFileInfo::groupId | ( | ) | const |
Returns the id of the group the file belongs to.
On Windows and on systems where files do not have groups this function always returns (uint) -2.
info-about-target-not-symlink
Definition at line 1461 of file qfileinfo.cpp.
|
inline |
Returns true
if the file system entry's path is absolute, otherwise returns false
(that is, the path is relative).
qresource-virtual-fs-colon
Definition at line 121 of file qfileinfo.h.
bool QFileInfo::isAlias | ( | ) | const |
Returns true
if this object points to an alias; otherwise returns false
.
Aliases only exist on \macos. They are treated as regular files, so opening an alias will open the file itself. In order to open the file or directory an alias references use symLinkTarget().
Definition at line 1273 of file qfileinfo.cpp.
bool QFileInfo::isBundle | ( | ) | const |
true
if this object points to a bundle or to a symbolic link to a bundle on \macos and iOS; otherwise returns false
.info-about-target-not-symlink
Definition at line 1109 of file qfileinfo.cpp.
bool QFileInfo::isDir | ( | ) | const |
Returns true
if this object points to a directory or to a symbolic link to a directory.
Returns false
if the object points to something that is not a directory (such as a file) or that does not exist.
info-about-target-not-symlink
Definition at line 1090 of file qfileinfo.cpp.
bool QFileInfo::isExecutable | ( | ) | const |
Returns \c true if the file system entry this QFileInfo refers to is executable; otherwise returns \c false.
! [info-about-target-not-symlink] If the file is a symlink, this function returns information about the target, not the symlink. ! [info-about-target-not-symlink]
\sa isReadable(), isWritable(), permission()
Definition at line 1008 of file qfileinfo.cpp.
bool QFileInfo::isFile | ( | ) | const |
Returns true
if this object points to a file or to a symbolic link to a file.
Returns false
if the object points to something that is not a file (such as a directory) or that does not exist.
info-about-target-not-symlink
Definition at line 1071 of file qfileinfo.cpp.
bool QFileInfo::isHidden | ( | ) | const |
Returns true
if the file system entry this QFileInfo refers to is ‘hidden’; otherwise returns false
.
{Note:} This function returns true
for the special entries "." and ".." on Unix, even though QDir::entryList treats them as shown. And note that, since this function inspects the file name, on Unix it will inspect the name of the symlink, if this file is a symlink, not the target's name.
On Windows, this function returns true
if the target file is hidden (not the symlink).
Definition at line 1029 of file qfileinfo.cpp.
bool QFileInfo::isJunction | ( | ) | const |
Returns true
if the object points to a junction; otherwise returns false
.
Junctions only exist on Windows' NTFS file system, and are typically created by the {mklink} command. They can be thought of as symlinks for directories, and can only be created for absolute paths on the local volume.
Definition at line 1293 of file qfileinfo.cpp.
bool QFileInfo::isNativePath | ( | ) | const |
true
if the file path can be used directly with native APIs. Returns false
if the file is otherwise supported by a virtual file system inside Qt, such as \l{the Qt Resource System}.{Note:} Native paths may still require conversion of path separators and character encoding, depending on platform and input requirements of the native API.
Definition at line 1051 of file qfileinfo.cpp.
bool QFileInfo::isOther | ( | ) | const |
Returns true
if this QFileInfo refers to a file system entry that is not a directory, regular file or symbolic link. Otherwise returns false
.
If this QFileInfo refers to a nonexistent entry, this method returns false
.
If the entry is a dangling symbolic link (the target doesn't exist), this method returns false
. For a non-dangling symbolic link, this function returns information about the target, not the symbolic link.
On Unix a special (other) file system entry is a FIFO, socket, character device, or block device. For more details, see the \l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html}{mknod}
manual page.
On Windows (for historical reasons, see \l{Symbolic Links and Shortcuts}) this method returns true
for .lnk files.
Definition at line 1205 of file qfileinfo.cpp.
bool QFileInfo::isReadable | ( | ) | const |
Returns true
if the user can read the file system entry this QFileInfo refers to; otherwise returns false
.
info-about-target-not-symlink
Definition at line 968 of file qfileinfo.cpp.
bool QFileInfo::isRelative | ( | ) | const |
Returns true
if the file system entry's path is relative, otherwise returns false
(that is, the path is absolute).
absolute-path-unix-windows
qresource-virtual-fs-colon
Definition at line 686 of file qfileinfo.cpp.
bool QFileInfo::isRoot | ( | ) | const |
Returns true
if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false
.
Definition at line 1307 of file qfileinfo.cpp.
bool QFileInfo::isShortcut | ( | ) | const |
Returns true
if this object points to a shortcut; otherwise returns false
.
Shortcuts only exist on Windows and are typically .lnk files. For instance, true will be returned for shortcuts (
*
.lnk files) on Windows, but false will be returned on Unix (including \macos and iOS).
The shortcut (.lnk) files are treated as regular files. Opening those will open the .lnk file itself. In order to open the file a shortcut references to, it must uses symLinkTarget() on a shortcut.
Definition at line 1249 of file qfileinfo.cpp.
bool QFileInfo::isSymbolicLink | ( | ) | const |
Returns true
if this object points to a symbolic link; otherwise returns false
.
Symbolic links exist on Unix (including \macos and iOS) and Windows (NTFS-symlink) and are typically created by the {ln -s} or
{mklink} commands, respectively.
Unix handles symlinks transparently. Opening a symbolic link effectively opens the \l{symLinkTarget()}{link's target}.
In contrast to isSymLink(), false will be returned for shortcuts (*
.lnk files) on Windows and aliases on \macos. Use QFileInfo::isShortcut() and QFileInfo::isAlias() instead.
symlink-target-exists-behavior
Definition at line 1172 of file qfileinfo.cpp.
bool QFileInfo::isSymLink | ( | ) | const |
Returns \c true if this object points to a symbolic link, shortcut, or alias; otherwise returns \c false. Symbolic links exist on Unix (including \macos and iOS) and Windows and are typically created by the \c{ln -s} or \c{mklink} commands, respectively. Opening a symbolic link effectively opens the \l{symLinkTarget()}{link's target}. In addition, true will be returned for shortcuts (\c *.lnk files) on Windows, and aliases on \macos. This behavior is deprecated and will likely change in a future version of Qt. Opening a shortcut or alias will open the \c .lnk or alias file itself. Example: \snippet code/src_corelib_io_qfileinfo.cpp 9
! [symlink-target-exists-behavior]
true
if the symlink points to an existing target, otherwise it returns false
. ! [symlink-target-exists-behavior] \sa isFile(), isDir(), symLinkTarget()
Definition at line 1143 of file qfileinfo.cpp.
bool QFileInfo::isWritable | ( | ) | const |
Returns true
if the user can write to the file system entry this QFileInfo refers to; otherwise returns false
.
info-about-target-not-symlink
Definition at line 988 of file qfileinfo.cpp.
QString QFileInfo::junctionTarget | ( | ) | const |
Resolves an NTFS junction to the path it references.
Returns the absolute path to the directory an NTFS junction points to, or an empty string if the object is not an NTFS junction.
There is no guarantee that the directory named by the NTFS junction actually exists.
Definition at line 1383 of file qfileinfo.cpp.
|
inline |
Returns the date and time when the file was last modified.
info-about-target-not-symlink
This function overloads \l{QFileInfo::lastModified(const QTimeZone &)}, and returns the same as {lastModified(QTimeZone::LocalTime)}.
Definition at line 162 of file qfileinfo.h.
Returns the date and time when the file was last modified.
file-times-in-time-zone
info-about-target-not-symlink
Definition at line 168 of file qfileinfo.h.
|
inline |
Returns the date and time when the file was last read (accessed).
On platforms where this information is not available, returns the same time as lastModified().
info-about-target-not-symlink
This function overloads \l{QFileInfo::lastRead(const QTimeZone &)}, and returns the same as {lastRead(QTimeZone::LocalTime)}.
Definition at line 163 of file qfileinfo.h.
Returns the date and time when the file was last read (accessed).
file-times-in-time-zone
On platforms where this information is not available, returns the same time as lastModified().
info-about-target-not-symlink
Definition at line 169 of file qfileinfo.h.
bool QFileInfo::makeAbsolute | ( | ) |
If the file system entry's path is relative, this method converts it to an absolute path and returns true
; if the path is already absolute, this method returns false
.
Definition at line 703 of file qfileinfo.cpp.
|
inline |
Returns the date and time when the file's metadata was last changed, in local time.
A metadata change occurs when the file is first created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions).
info-about-target-not-symlink
This function overloads QFileInfo::metadataChangeTime(const QTimeZone &tz), and returns the same as {metadataChangeTime(QTimeZone::LocalTime)}.
Definition at line 161 of file qfileinfo.h.
Returns the date and time when the file's metadata was last changed.
A metadata change occurs when the file is first created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions).
file-times-in-time-zone
info-about-target-not-symlink
Definition at line 167 of file qfileinfo.h.
Move-assigns other to this QFileInfo instance.
Makes a copy of the given fileinfo and assigns it to this QFileInfo.
\class QFileInfo \inmodule QtCore \reentrant \brief The QFileInfo class provides an OS-independent API to retrieve information about file system entries. \ingroup io \ingroup shared \compares equality QFileInfo provides information about a file system entry, such as its name, path, access rights and whether it is a regular file, directory or symbolic link. The entry's size and last modified/read times are also available. QFileInfo can also be used to obtain information about a Qt \l{resource system}{resource}. A QFileInfo can point to a file system entry with either an absolute or a relative path: \list \li \include qfileinfo.cpp absolute-path-unix-windows \li \include qfileinfo.cpp relative-path-note \endlist An example of an absolute path is the string \c {"/tmp/quartz"}. A relative path may look like \c {"src/fatlib"}. You can use the function isRelative() to check whether a QFileInfo is using a relative or an absolute path. You can call the function makeAbsolute() to convert a relative QFileInfo's path to an absolute path.
! [qresource-virtual-fs-colon]
The file system entry path that the QFileInfo works on is set in the constructor or later with setFile(). Use exists() to see if the entry actually exists and size() to get its size. The file system entry's type is obtained with isFile(), isDir(), and isSymLink(). The symLinkTarget() function provides the absolute path of the target the symlink points to. The path elements of the file system entry can be extracted with path() and fileName(). The fileName()'s parts can be extracted with baseName(), suffix(), or completeSuffix(). QFileInfo objects referring to directories created by Qt classes will not have a trailing directory separator \c{'/'}. If you wish to use trailing separators in your own file info objects, just append one to the entry's path given to the constructors or setFile(). Date and time related information are returned by birthTime(), fileTime(), lastModified(), lastRead(), and metadataChangeTime(). Information about access permissions can be obtained with isReadable(), isWritable(), and isExecutable(). Ownership information can be obtained with owner(), ownerId(), group(), and groupId(). You can also examine permissions and ownership in a single statement using the permission() function. \section1 Symbolic Links and Shortcuts On Unix (including \macos and iOS), the property getter functions in this class return the properties such as times and size of the target, not the symlink, because Unix handles symlinks transparently. Opening a symlink using QFile effectively opens the link's target. For example: \snippet code/src_corelib_io_qfileinfo.cpp 0 On Windows, shortcuts (\c .lnk files) are currently treated as symlinks. As on Unix systems, the property getters return the size of the target, not the \c .lnk file itself. This behavior is deprecated and will likely be removed in a future version of Qt, after which \c .lnk files will be treated as regular files. \snippet code/src_corelib_io_qfileinfo.cpp 1 \section1 NTFS permissions On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line: \snippet ntfsp.cpp 0 Permission checking is then turned on and off by incrementing and decrementing \c qt_ntfs_permission_lookup by 1. \snippet ntfsp.cpp 1 \note Since this is a non-atomic global variable, it is only safe to increment or decrement \c qt_ntfs_permission_lookup before any threads other than the main thread have started or after every thread other than the main thread has ended. \note From Qt 6.6 the variable \c qt_ntfs_permission_lookup is deprecated. Please use the following alternatives. The safe and easy way to manage permission checks is to use the RAII class \c QNtfsPermissionCheckGuard. \snippet ntfsp.cpp raii If you need more fine-grained control, it is possible to manage the permission with the following functions instead: \snippet ntfsp.cpp free-funcs \section1 Performance Considerations Some of QFileInfo's functions have to query the file system, but for performance reasons, some functions only operate on the path string. For example: To return the absolute path of a relative entry's path, absolutePath() has to query the file system. The path() function, however, can work on the file name directly, and so it is faster. QFileInfo also caches information about the file system entry it refers to. Because the file system can be changed by other users or programs, or even by other parts of the same program, there is a function that refreshes the information stored in QFileInfo, namely refresh(). To switch off a QFileInfo's caching (that is, force it to query the underlying file system every time you request information from it), call setCaching(false). Fetching information from the file system is typically done by calling (possibly) expensive system functions, so QFileInfo (depending on the implementation) might not fetch all the information from the file system at construction. To make sure that all information is read from the file system immediately, use the stat() member function. \l{birthTime()}, \l{fileTime()}, \l{lastModified()}, \l{lastRead()}, and \l{metadataChangeTime()} return times in \e{local time} by default. Since native file system API typically uses UTC, this requires a conversion. If you don't actually need the local time, you can avoid this by requesting the time in QTimeZone::UTC directly. \section1 Platform Specific Issues \include android-content-uri-limitations.qdocinc \sa QDir, QFile
Definition at line 484 of file qfileinfo.cpp.
QString QFileInfo::owner | ( | ) | const |
Returns the owner of the file.
On systems where files do not have owners, or if an error occurs, an empty string is returned.
This function can be time consuming under Unix (in the order of milliseconds). On Windows, it will return an empty string unless the \l{NTFS permissions} check has been enabled.
info-about-target-not-symlink
Definition at line 1404 of file qfileinfo.cpp.
uint QFileInfo::ownerId | ( | ) | const |
Returns the id of the owner of the file.
On Windows and on systems where files do not have owners this function returns ((uint) -2).
info-about-target-not-symlink
Definition at line 1422 of file qfileinfo.cpp.
QString QFileInfo::path | ( | ) | const |
Returns the path of the file system entry this QFileInfo refers to, excluding the entry's name.
path-ends-with-slash-empty-name-component In this case, this function will return the entire path.
Definition at line 657 of file qfileinfo.cpp.
bool QFileInfo::permission | ( | QFile::Permissions | permissions | ) | const |
Tests for file permissions.
The permissions argument can be several flags of type QFile::Permissions OR-ed together to check for permission combinations.
On systems where files do not have permissions this function always returns true
.
Example:
info-about-target-not-symlink
Definition at line 1488 of file qfileinfo.cpp.
QFile::Permissions QFileInfo::permissions | ( | ) | const |
Returns the complete OR-ed together combination of QFile::Permissions for the file.
info-about-target-not-symlink
Definition at line 1511 of file qfileinfo.cpp.
QString QFileInfo::readSymLink | ( | ) | const |
Returns the raw path referenced by the symbolic link, without resolving a relative path relative to the directory containing the symbolic link. The returned string will only be an absolute path if the symbolic link actually references it as such. Returns an empty string if the object is not a symbolic link.
Definition at line 1361 of file qfileinfo.cpp.
void QFileInfo::refresh | ( | ) |
Refreshes the information about the file system entry this QFileInfo refers to, that is, reads in information from the file system the next time a cached property is fetched.
Definition at line 764 of file qfileinfo.cpp.
void QFileInfo::setCaching | ( | bool | enable | ) |
If enable is true, enables caching of file information.
If enable is false caching is disabled.
When caching is enabled, QFileInfo reads the file information from the file system the first time it's needed, but generally not later.
Caching is enabled by default.
Definition at line 1776 of file qfileinfo.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the path of the file system entry that this QFileInfo provides information about to path in directory dir.
preserve-relative-or-absolute
Definition at line 550 of file qfileinfo.cpp.
void QFileInfo::setFile | ( | const QFileDevice & | file | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the file that the QFileInfo provides information about to file.
If file includes a relative path, the QFileInfo will also have a relative path.
Definition at line 535 of file qfileinfo.cpp.
Sets the path of the file system entry that this QFileInfo provides information about to \a path that can be absolute or relative.
! [absolute-path-unix-windows] On Unix, absolute paths begin with the directory separator {'/'}
. On Windows, absolute paths begin with a drive specification (for example, {D:/}
). ! [ absolute-path-unix-windows]
! [relative-path-note] Relative paths begin with a directory name or a regular file name and specify a file system entry's path relative to the current working directory. ! [relative-path-note]
Example: \snippet code/src_corelib_io_qfileinfo.cpp 2 \sa isRelative(), QDir::setCurrent(), QDir::isRelativePath()
Definition at line 517 of file qfileinfo.cpp.
qint64 QFileInfo::size | ( | ) | const |
Returns the file size in bytes.
If the file does not exist or cannot be fetched, 0 is returned.
info-about-target-not-symlink
Definition at line 1531 of file qfileinfo.cpp.
void QFileInfo::stat | ( | ) |
Reads all attributes from the file system.
This is useful when information about the file system is collected in a worker thread, and then passed to the UI in the form of caching QFileInfo instances.
Definition at line 1792 of file qfileinfo.cpp.
QString QFileInfo::suffix | ( | ) | const |
Returns the suffix (extension) of the file.
The suffix consists of all characters in the file after (but not including) the last '.'.
Example:
The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").
Definition at line 910 of file qfileinfo.cpp.
Definition at line 61 of file qfileinfo.h.
QString QFileInfo::symLinkTarget | ( | ) | const |
Returns the absolute path to the file or directory a symbolic link points to, or an empty string if the object isn't a symbolic link.
This name may not represent an existing file; it is only a string.
symlink-target-exists-behavior
Definition at line 1342 of file qfileinfo.cpp.
Definition at line 450 of file qfileinfo.cpp.
|
friend |
Definition at line 24 of file qfileinfo.h.
|
friend |
Definition at line 25 of file qfileinfo.h.
Synonym for QList<QFileInfo>.
Definition at line 191 of file qfileinfo.h.
|
friend |
Definition at line 26 of file qfileinfo.h.
|
protected |
Definition at line 177 of file qfileinfo.h.