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

#include <qfileinfo.h>

+ Collaboration diagram for QFileInfo:

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.
 
QFileInfooperator= (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 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< QFileInfoPrivated_ptr
 

Friends

class QDirIteratorPrivate
 
class QDirListingPrivate
 
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>.
 

Detailed Description

Definition at line 22 of file qfileinfo.h.

Constructor & Destructor Documentation

◆ QFileInfo() [1/6]

QFileInfo::QFileInfo ( QFileInfoPrivate * p)
explicit

Definition at line 346 of file qfileinfo.cpp.

◆ QFileInfo() [2/6]

QFileInfo::QFileInfo ( )

Constructs an empty QFileInfo object that doesn't refer to any file system entry.

See also
setFile()

Definition at line 356 of file qfileinfo.cpp.

Referenced by exists(), and setFile().

+ Here is the caller graph for this function:

◆ QFileInfo() [3/6]

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() [4/6]

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.

See also
isRelative()

Definition at line 383 of file qfileinfo.cpp.

◆ QFileInfo() [5/6]

QFileInfo::QFileInfo ( const QDir & dir,
const QString & path )
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() [6/6]

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::~QFileInfo ( )

Destroys the QFileInfo and frees its resources.

Definition at line 419 of file qfileinfo.cpp.

Member Function Documentation

◆ absoluteDir()

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.

// Given a current working directory of "/home/user/Documents/memos/"
QFileInfo info1(u"relativeFile"_s);
qDebug() << info1.absolutePath(); // "/home/user/Documents/memos/"
qDebug() << info1.baseName(); // "relativeFile"
qDebug() << info1.absoluteDir(); // QDir(u"/home/user/Documents/memos"_s)
qDebug() << info1.absoluteDir().path(); // "/home/user/Documents/memos"
// A QFileInfo on a dir
QFileInfo info2(u"/home/user/Documents/memos"_s);
qDebug() << info2.absolutePath(); // "/home/user/Documents"
qDebug() << info2.baseName(); // "memos"
qDebug() << info2.absoluteDir(); // QDir(u"/home/user/Documents"_s)
qDebug() << info2.absoluteDir().path(); // "/home/user/Documents"
See also
dir(), filePath(), fileName(), isRelative()

Definition at line 950 of file qfileinfo.cpp.

References absolutePath().

Referenced by changeInstallName(), deployRPaths(), and qRelocateResourceFile().

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

◆ absoluteFilePath()

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 578 of file qfileinfo.cpp.

References QAbstractFileEngine::AbsoluteName, and d.

Referenced by TestCaseCollector::TestCaseCollector(), QDirEntryInfo::absoluteFilePath(), QQmlTypeLoader::absoluteFilePath(), QPixmapIconEngine::addFile(), QQmlJSLinter::applyFixes(), QDir::cd(), changeInstallName(), codesignBundle(), deploy(), deployRPaths(), deployTranslations(), deployWebEngineCore(), QGtk3Interface::fileIcon(), QConfFile::fromName(), QUrl::fromUserInput(), QFileInfoGatherer::getInfo(), QQmlPluginImporter::importDynamicPlugin(), QSSGAssetImportManager::importFile(), QQmlPluginImporter::importPlugins(), QQmlJSLinter::lintFile(), loadModelShapeMesh(), makeAbsolute(), QRhiMetal::pipelineCacheData(), QQmlDataBlob::SourceCodeData::readAll(), Viewer::saveImage(), scanImports(), QRhiMetal::setPipelineCacheData(), translateDriveName(), QQuickFileDialogImplPrivate::updateSelectedFile(), RCCFileInfo::writeDataBlob(), and QQmlToolingSettings::writeDefaults().

+ Here is the caller graph for this function:

◆ absolutePath()

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.

Warning
If filePath() is empty the behavior of this function is undefined.
See also
absoluteFilePath(), path(), canonicalPath(), fileName(), isRelative()

Definition at line 621 of file qfileinfo.cpp.

References QAbstractFileEngine::AbsolutePathName, and d.

Referenced by absoluteDir(), QDirEntryInfo::absolutePath(), QTranslatorPrivate::do_load(), findFilesRecursively(), findMinGWRuntimePaths(), QQmlPluginImporter::importDynamicPlugin(), QCss::Parser::init(), QQmlDataTest::initTestCase(), QConfFile::isWritable(), readInputFile(), and writeDependencyFile().

+ Here is the caller graph for this function:

◆ baseName()

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:

QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.baseName(); // base = "archive"

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

See also
fileName(), suffix(), completeSuffix(), completeBaseName()

Definition at line 842 of file qfileinfo.cpp.

References QAbstractFileEngine::BaseName, QFileSystemEntry::baseName(), and d.

Referenced by detectLatestAndroidPlatform(), QDeferredFactory< QQmlJSScope >::internalName(), parseProvider(), and QImageReader::read().

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

◆ birthTime() [1/2]

QDateTime QFileInfo::birthTime ( ) const
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)}.

Since
5.10
See also
lastModified(), lastRead(), metadataChangeTime(), fileTime()

Definition at line 158 of file qfileinfo.h.

References QFileDevice::FileBirthTime.

◆ birthTime() [2/2]

QDateTime QFileInfo::birthTime ( const QTimeZone & tz) const
inline

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

Since
6.6
See also
lastModified(const QTimeZone &), lastRead(const QTimeZone &), metadataChangeTime(const QTimeZone &), fileTime(QFileDevice::FileTime, const QTimeZone &)

Definition at line 164 of file qfileinfo.h.

References QFileDevice::FileBirthTime.

◆ bundleName()

QString QFileInfo::bundleName ( ) const
Since
4.3 Returns the name of the bundle.

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:

QFileInfo fi("/Applications/Safari.app");
QString bundle = fi.bundleName(); // name = "Safari"
See also
isBundle(), filePath(), baseName(), suffix()

Definition at line 818 of file qfileinfo.cpp.

References QAbstractFileEngine::BundleName, and d.

Referenced by QDirEntryInfo::bundleName().

+ Here is the caller graph for this function:

◆ caching()

bool QFileInfo::caching ( ) const

Returns true if caching is enabled; otherwise returns false.

See also
setCaching(), refresh()

Definition at line 1705 of file qfileinfo.cpp.

References d.

Referenced by setFile().

+ Here is the caller graph for this function:

◆ canonicalFilePath()

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.

See also
filePath(), absoluteFilePath(), dir()

Definition at line 596 of file qfileinfo.cpp.

References QAbstractFileEngine::CanonicalName, and d.

Referenced by QFseventsFileSystemWatcherEngine::addPaths(), QCoreApplication::applicationFilePath(), QDirEntryInfo::canonicalFilePath(), changeInstallName(), QCocoaFileIconEngine::filePixmap(), QQmlJS::Dom::QmldirFile::fromPathAndCode(), QFileInfoGatherer::getInfo(), QDefaultOutputMapping::load(), QQmlJSResourceFileMapper::localFileFilter(), parseOptions(), pythonRoot(), and resolveFileName().

+ Here is the caller graph for this function:

◆ canonicalPath()

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.

See also
path(), absolutePath()

Definition at line 638 of file qfileinfo.cpp.

References QAbstractFileEngine::CanonicalPathName, and d.

Referenced by changeInstallName(), and QQmlJSImportVisitor::implicitImportDirectory().

+ Here is the caller graph for this function:

◆ completeBaseName()

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:

QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.completeBaseName(); // base = "archive.tar"
See also
fileName(), suffix(), completeSuffix(), baseName()

Definition at line 863 of file qfileinfo.cpp.

References QAbstractFileEngine::BaseName, QFileSystemEntry::completeBaseName(), and d.

Referenced by Scanner::process().

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

◆ completeSuffix()

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:

QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.completeSuffix(); // ext = "tar.gz"
See also
fileName(), suffix(), baseName(), completeBaseName()

Definition at line 885 of file qfileinfo.cpp.

References d.

Referenced by QLibrary::isLibrary(), QV4::CompiledData::CompilationUnit::localCacheFilePath(), and QQuickNinePatchImage::pixmapChange().

+ Here is the caller graph for this function:

◆ dir()

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.

Note
The QDir returned always corresponds to the object's parent directory, even if the QFileInfo represents a directory.

For each of the following, dir() returns the QDir {"~/examples/191697"}.

QFileInfo fileInfo1("~/examples/191697/.");
QFileInfo fileInfo2("~/examples/191697/..");
QFileInfo fileInfo3("~/examples/191697/main.cpp");

For each of the following, dir() returns the QDir {"."}.

QFileInfo fileInfo4(".");
QFileInfo fileInfo5("..");
QFileInfo fileInfo6("main.cpp");
See also
absolutePath(), filePath(), fileName(), isRelative(), absoluteDir()

Definition at line 936 of file qfileinfo.cpp.

References d.

Referenced by Moc::parsePluginData(), QQmlToolingSettings::search(), setFile(), QQuickFileDialogImpl::setInitialCurrentFolderAndSelectedFile(), QQmlJS::Dom::QQmlDomAstCreator::visit(), and QQmlJS::Dom::QQmlDomAstCreator::visit().

+ Here is the caller graph for this function:

◆ exists() [1/2]

bool QFileInfo::exists ( ) const

Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false.

Note
If the entry is a symlink that points to a non-existing target, this method returns false.

Definition at line 718 of file qfileinfo.cpp.

References d, QFileSystemMetaData::ExistsAttribute, QAbstractFileEngine::ExistsFlag, and QFileSystemEngine::fillMetaData().

Referenced by QSSGShaderCache::QSSGShaderCache(), checkNeedPortalSupport(), checkNeedPortalSupport(), copyDylib(), QQmlTypeLoader::directoryExists(), existingImageFileForPath(), QFile::exists(), QDir::exists(), findInPath(), QUrl::fromUserInput(), QFileInfoGatherer::getInfo(), QSSGAssetImportManager::getOptionsForFile(), QQuickFileDialogImplPrivate::handleClick(), iconTempPath(), QSSGAssetImportManager::importFile(), importImp(), QConfFile::isWritable(), loadModelShapeMesh(), QFileDialogPrivate::pathChanged(), QTest::qFindTestData(), QWindowsFileSystemWatcherEngineThread::run(), scanImports(), QExtendedInformation::size(), QQuickFolderBreadcrumbBarPrivate::textFieldAccepted(), and QExtendedInformation::type().

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

◆ exists() [2/2]

bool QFileInfo::exists ( const QString & path)
static
Since
5.2

Returns true if the file system entry path exists; otherwise returns false.

Note
If path is a symlink that points to a non-existing target, this method returns false.
Using this function is faster than using QFileInfo(path).exists() for file system access.

Definition at line 743 of file qfileinfo.cpp.

References QFileInfo(), QFileSystemEngine::createLegacyEngine(), engine, QFileSystemMetaData::exists(), QFileSystemMetaData::ExistsAttribute, and QFileSystemEngine::fillMetaData().

+ Here is the call graph for this function:

◆ fileName()

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]

Note
If this QFileInfo is given a path ending with a directory separator {'/'}, the entry's name part is considered empty. ! [path-ends-with-slash-empty-name-component]
\sa isRelative(), filePath(), baseName(), suffix()

Definition at line 796 of file qfileinfo.cpp.

References QAbstractFileEngine::BaseName, and d.

Referenced by QFileDialogArgs::QFileDialogArgs(), QAbstractFileIconEngine::cacheKey(), QWindowsFileIconEngine::cacheKey(), changeInstallName(), QFSFileEngineIterator::currentFileName(), deploy(), deployWebEngineCore(), determinePluginLibrary(), QAndroidStyle::AndroidImageDrawable::draw(), QAndroidStyle::Android9PatchDrawable::draw(), QDirIterator::fileName(), QmlLsp::QQmlCodeModel::fileNamesToWatch(), QtWaylandClient::getIconSvg(), main(), patchQtCore(), QQuickImageSelector::setUrl(), JsonOutput::toList(), translateDriveName(), updateFile(), QQuickFileDialogImplPrivate::updateFileNameTextEdit(), QWidget::windowTitle(), RCCFileInfo::writeDataBlob(), writeEtw(), and writeLttng().

+ Here is the caller graph for this function:

◆ filePath()

QString QFileInfo::filePath ( ) const

Returns the path of the file system entry this QFileInfo refers to; the path may be absolute or relative.

See also
absoluteFilePath(), canonicalFilePath(), isRelative()

Definition at line 774 of file qfileinfo.cpp.

References d.

Referenced by QAbstractFileEngineIterator::currentFileInfo(), deployWebEngineCore(), QDirIterator::filePath(), QtWaylandClient::getIconSvg(), QFileInfoGatherer::getInfo(), QMimeDatabase::mimeTypeForFile(), QDirIterator::next(), and QCocoaFileDialogHelper::selectFile().

+ Here is the caller graph for this function:

◆ fileTime() [1/2]

QDateTime QFileInfo::fileTime ( QFile::FileTime time) const

Referenced by QDirEntryInfo::fileTime().

+ Here is the caller graph for this function:

◆ fileTime() [2/2]

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 1666 of file qfileinfo.cpp.

References QFileSystemMetaData::AccessTime, QFileSystemMetaData::BirthTime, d, QFileDevice::FileAccessTime, QFileDevice::FileBirthTime, QFileDevice::FileMetadataChangeTime, QFileDevice::FileModificationTime, QFileSystemMetaData::MetadataChangeTime, QFileSystemMetaData::ModificationTime, time, and QDateTime::toTimeZone().

+ Here is the call graph for this function:

◆ group()

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

See also
groupId(), owner(), ownerId()

Definition at line 1390 of file qfileinfo.cpp.

References d, and QAbstractFileEngine::OwnerGroup.

◆ groupId()

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

See also
group(), owner(), ownerId()

Definition at line 1408 of file qfileinfo.cpp.

References d, QFileSystemMetaData::GroupId, and QAbstractFileEngine::OwnerGroup.

Referenced by QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), and QWindowsFileSystemWatcherEngine::PathInfo::operator=().

+ Here is the caller graph for this function:

◆ isAbsolute()

bool QFileInfo::isAbsolute ( ) const
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

See also
isRelative()

Definition at line 120 of file qfileinfo.h.

References isRelative().

Referenced by _qt_get_directory(), QTextDocument::loadResource(), and QTextBrowserPrivate::resolveUrl().

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

◆ isAlias()

bool QFileInfo::isAlias ( ) const

Returns true if this object points to an alias; otherwise returns false.

Since
6.4

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

Note
Even if an alias points to a non existing file, isAlias() returns true.
See also
isFile(), isDir(), isSymLink(), symLinkTarget()

Definition at line 1220 of file qfileinfo.cpp.

References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.

◆ isBundle()

bool QFileInfo::isBundle ( ) const
Since
4.3 Returns 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

See also
isDir(), isSymLink(), isFile()

Definition at line 1107 of file qfileinfo.cpp.

References QAbstractFileEngine::BundleType, QFileSystemMetaData::BundleType, and d.

◆ isDir()

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

See also
isFile(), isSymLink(), isBundle()

Definition at line 1088 of file qfileinfo.cpp.

References d, QAbstractFileEngine::DirectoryType, and QFileSystemMetaData::DirectoryType.

Referenced by QFileDialogArgs::QFileDialogArgs(), QQuickFileDialogDelegatePrivate::chooseFile(), deployWebEngineCore(), QQmlTypeLoader::directoryExists(), QWindowsFileIconEngine::filePixmap(), QQuickFileDialogImplPrivate::handleClick(), QFileSystemModel::isDir(), QMimeDatabasePrivate::mimeTypeForFile(), QDirSortItemComparator::operator()(), QQmlToolingSettings::search(), QQuickFolderBreadcrumbBarPrivate::textFieldAccepted(), QExtendedInformation::type(), and vcRedistDir().

+ Here is the caller graph for this function:

◆ isExecutable()

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 1006 of file qfileinfo.cpp.

References d, QAbstractFileEngine::ExeUserPerm, and QFileSystemMetaData::UserExecutePermission.

Referenced by QAbstractFileIconEngine::cacheKey(), and findInPath().

+ Here is the caller graph for this function:

◆ isFile()

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

See also
isDir(), isSymLink(), isBundle()

Definition at line 1069 of file qfileinfo.cpp.

References d, QAbstractFileEngine::FileType, and QFileSystemMetaData::FileType.

Referenced by QQmlTypeLoader::absoluteFilePath(), QAbstractFileIconEngine::cacheKey(), deploy(), existsAsSpecified(), findInPath(), QFileInfoGatherer::getInfo(), QmlDirectoryFileEntryFunction::operator()(), QFileSystemModel::remove(), QExtendedInformation::type(), and QQuickFileDialogImplPrivate::updateFileNameTextEdit().

+ Here is the caller graph for this function:

◆ isHidden()

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 1027 of file qfileinfo.cpp.

References d, QFileSystemMetaData::HiddenAttribute, and QAbstractFileEngine::HiddenFlag.

Referenced by QExtendedInformation::isHidden().

+ Here is the caller graph for this function:

◆ isJunction()

bool QFileInfo::isJunction ( ) const
Since
5.15

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 1240 of file qfileinfo.cpp.

References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.

◆ isNativePath()

bool QFileInfo::isNativePath ( ) const
Since
5.0 Returns 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.

See also
QDir::toNativeSeparators(), QFile::encodeName(), filePath(), absoluteFilePath(), canonicalFilePath()

Definition at line 1049 of file qfileinfo.cpp.

References d, and QAbstractFileEngine::LocalDiskFlag.

Referenced by QMimeDatabasePrivate::mimeTypeForFile().

+ Here is the caller graph for this function:

◆ isReadable()

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

Note
If the \l{NTFS permissions} check has not been enabled, the result on Windows will merely reflect whether the entry exists.
See also
isWritable(), isExecutable(), permission()

Definition at line 966 of file qfileinfo.cpp.

References d, QAbstractFileEngine::ReadUserPerm, and QFileSystemMetaData::UserReadPermission.

Referenced by QTextBrowserPrivate::findFile(), and QFileInfoGatherer::getInfo().

+ Here is the caller graph for this function:

◆ isRelative()

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

See also
isAbsolute()

Definition at line 684 of file qfileinfo.cpp.

References d.

Referenced by QDir::isRelativePath(), QAndroidCaptureSession::start(), and QQmlJSImportVisitor::visit().

+ Here is the caller graph for this function:

◆ isRoot()

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 1254 of file qfileinfo.cpp.

References d, QFileSystemMetaData::ExistsAttribute, QFileSystemEngine::fillMetaData(), and QAbstractFileEngine::RootFlag.

Referenced by QWindowsFileIconEngine::filePixmap().

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

◆ isShortcut()

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.

Note
Even if a shortcut (broken shortcut) points to a non existing file, isShortcut() returns true.
See also
isFile(), isDir(), isSymbolicLink(), symLinkTarget()

Definition at line 1196 of file qfileinfo.cpp.

References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.

◆ isSymbolicLink()

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

See also
isFile(), isDir(), isShortcut(), symLinkTarget()

Definition at line 1170 of file qfileinfo.cpp.

References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.

◆ isSymLink()

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]

Note
exists() returns true if the symlink points to an existing target, otherwise it returns false. ! [symlink-target-exists-behavior]
\sa isFile(), isDir(), symLinkTarget()

Definition at line 1141 of file qfileinfo.cpp.

References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.

Referenced by QAbstractFileIconEngine::cacheKey(), QFileDialogPrivate::deleteCurrent(), QFileInfoGatherer::getInfo(), QExtendedInformation::isSymLink(), QFileSystemModel::remove(), QExtendedInformation::size(), and QExtendedInformation::type().

+ Here is the caller graph for this function:

◆ isWritable()

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

Note
If the \l{NTFS permissions} check has not been enabled, the result on Windows will merely reflect whether the entry is marked as Read Only.
See also
isReadable(), isExecutable(), permission()

Definition at line 986 of file qfileinfo.cpp.

References d, QFileSystemMetaData::UserWritePermission, and QAbstractFileEngine::WriteUserPerm.

Referenced by ensureWritableDir(), ensureWritableDir(), and qt_ensureWritableDir().

+ Here is the caller graph for this function:

◆ junctionTarget()

QString QFileInfo::junctionTarget ( ) const
Since
6.2

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.

See also
isJunction(), isFile(), isDir(), isSymLink(), isSymbolicLink(), isShortcut()

Definition at line 1330 of file qfileinfo.cpp.

References d, and QAbstractFileEngine::JunctionName.

◆ lastModified() [1/2]

QDateTime QFileInfo::lastModified ( ) const
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)}.

See also
birthTime(), lastRead(), metadataChangeTime(), fileTime()

Definition at line 160 of file qfileinfo.h.

References QFileDevice::FileModificationTime.

Referenced by QV4::ExecutionEngine::compileModule(), QLockFilePrivate::isApparentlyStale(), QExtendedInformation::lastModified(), QMimeBinaryProvider::CacheFile::load(), QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), QWindowsFileSystemWatcherEngine::PathInfo::operator=(), QExtendedInformation::operator==(), QLockFile::tryLock(), QV4::CompiledData::Unit::verifyHeader(), and RCCFileInfo::writeDataInfo().

+ Here is the caller graph for this function:

◆ lastModified() [2/2]

QDateTime QFileInfo::lastModified ( const QTimeZone & tz) const
inline

Returns the date and time when the file was last modified.

file-times-in-time-zone

info-about-target-not-symlink

Since
6.6
See also
birthTime(const QTimeZone &), lastRead(const QTimeZone &), metadataChangeTime(const QTimeZone &), fileTime(QFileDevice::FileTime, const QTimeZone &)

Definition at line 166 of file qfileinfo.h.

References QFileDevice::FileModificationTime.

◆ lastRead() [1/2]

QDateTime QFileInfo::lastRead ( ) const
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)}.

See also
birthTime(), lastModified(), metadataChangeTime(), fileTime()

Definition at line 161 of file qfileinfo.h.

References QFileDevice::FileAccessTime.

◆ lastRead() [2/2]

QDateTime QFileInfo::lastRead ( const QTimeZone & tz) const
inline

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

Since
6.6
See also
birthTime(const QTimeZone &), lastModified(const QTimeZone &), metadataChangeTime(const QTimeZone &), fileTime(QFileDevice::FileTime, const QTimeZone &)

Definition at line 167 of file qfileinfo.h.

References QFileDevice::FileAccessTime.

◆ makeAbsolute()

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.

See also
filePath(), isRelative()

Definition at line 701 of file qfileinfo.cpp.

References absoluteFilePath(), QSharedDataPointer< T >::constData(), d_ptr, QFileInfoPrivate::fileEntry, QFileInfoPrivate::isDefaultConstructed, QFileSystemEntry::isRelative(), and setFile().

+ Here is the call graph for this function:

◆ metadataChangeTime() [1/2]

QDateTime QFileInfo::metadataChangeTime ( ) const
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)}.

Since
5.10
See also
birthTime(), lastModified(), lastRead(), fileTime()

Definition at line 159 of file qfileinfo.h.

References QFileDevice::FileMetadataChangeTime.

◆ metadataChangeTime() [2/2]

QDateTime QFileInfo::metadataChangeTime ( const QTimeZone & tz) const
inline

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

Since
6.6
See also
birthTime(const QTimeZone &), lastModified(const QTimeZone &), lastRead(const QTimeZone &), fileTime(QFileDevice::FileTime time, const QTimeZone &)

Definition at line 165 of file qfileinfo.h.

References QFileDevice::FileMetadataChangeTime.

◆ operator=()

QFileInfo & QFileInfo::operator= ( const QFileInfo & fileinfo)

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]

Note
Paths starting with a colon ({:}) are always considered absolute, as they denote a QResource. ! [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
Since
5.2

Definition at line 480 of file qfileinfo.cpp.

References d_ptr.

◆ owner()

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

See also
ownerId(), group(), groupId()

Definition at line 1351 of file qfileinfo.cpp.

References d, and QAbstractFileEngine::OwnerUser.

◆ ownerId()

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

See also
owner(), group(), groupId()

Definition at line 1369 of file qfileinfo.cpp.

References d, QAbstractFileEngine::OwnerUser, and QFileSystemMetaData::UserId.

Referenced by QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), and QWindowsFileSystemWatcherEngine::PathInfo::operator=().

+ Here is the caller graph for this function:

◆ path()

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.

See also
filePath(), absolutePath(), canonicalPath(), dir(), fileName(), isRelative()

Definition at line 655 of file qfileinfo.cpp.

References d.

Referenced by QCoreApplication::applicationDirPath(), deployPlugins(), RCCResourceLibrary::readFiles(), and QQuickImageSelector::setUrl().

+ Here is the caller graph for this function:

◆ permission()

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.

Note
The result might be inaccurate on Windows if the \l{NTFS permissions} check has not been enabled.

Example:

QFileInfo fi("/tmp/archive.tar.gz");
if (fi.permission(QFile::WriteUser | QFile::ReadGroup))
qWarning("I can change the file; my group can read the file");
if (fi.permission(QFile::WriteGroup | QFile::WriteOther))
qWarning("The group or others can change the file");

info-about-target-not-symlink

See also
isReadable(), isWritable(), isExecutable()

Definition at line 1435 of file qfileinfo.cpp.

References d, and permissions().

+ Here is the call graph for this function:

◆ permissions()

QFile::Permissions QFileInfo::permissions ( ) const

Returns the complete OR-ed together combination of QFile::Permissions for the file.

Note
The result might be inaccurate on Windows if the \l{NTFS permissions} check has not been enabled.

info-about-target-not-symlink

Definition at line 1458 of file qfileinfo.cpp.

References d, QFileSystemMetaData::Permissions, and QAbstractFileEngine::PermsMask.

Referenced by QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), QWindowsFileSystemWatcherEngine::PathInfo::operator=(), QExtendedInformation::operator==(), permission(), and QExtendedInformation::permissions().

+ Here is the caller graph for this function:

◆ readSymLink()

QString QFileInfo::readSymLink ( ) const
Since
6.6 Read the path the symlink references.

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.

See also
symLinkTarget(), exists(), isSymLink(), isDir(), isFile()

Definition at line 1308 of file qfileinfo.cpp.

References d, and QAbstractFileEngine::RawLinkPath.

◆ refresh()

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 762 of file qfileinfo.cpp.

References d.

◆ setCaching()

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.

See also
refresh(), caching()

Definition at line 1723 of file qfileinfo.cpp.

References d.

◆ setFile() [1/3]

void QFileInfo::setFile ( const QDir & dir,
const QString & path )

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

See also
isRelative()

Definition at line 548 of file qfileinfo.cpp.

References dir(), QDir::filePath(), and setFile().

+ Here is the call graph for this function:

◆ setFile() [2/3]

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.

See also
isRelative()

Definition at line 533 of file qfileinfo.cpp.

References file, QFile::fileName(), and setFile().

+ Here is the call graph for this function:

◆ setFile() [3/3]

void QFileInfo::setFile ( const QString & path)
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 515 of file qfileinfo.cpp.

References QFileInfo(), QFileInfoPrivate::cache_enabled, caching(), QSharedDataPointer< T >::constData(), and d_ptr.

Referenced by QAbstractFileEngineIterator::currentFileInfo(), makeAbsolute(), Preprocessor::resolveInclude(), setFile(), setFile(), and QTest::setMainSourcePath().

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

◆ size()

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

See also
exists()

Definition at line 1478 of file qfileinfo.cpp.

References QFileInfoPrivate::CachedSize, d, and QFileSystemMetaData::SizeAttribute.

Referenced by main(), QQmlDataBlob::SourceCodeData::readAll(), QDirEntryInfo::size(), and QExtendedInformation::size().

+ Here is the caller graph for this function:

◆ stat()

void QFileInfo::stat ( )

Reads all attributes from the file system.

Since
6.0

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.

See also
setCaching(), refresh()

Definition at line 1739 of file qfileinfo.cpp.

References QFileSystemMetaData::AllMetaDataFlags, d, and QFileSystemEngine::fillMetaData().

+ Here is the call graph for this function:

◆ suffix()

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:

QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.suffix(); // ext = "gz"

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

See also
fileName(), completeSuffix(), baseName(), completeBaseName()

Definition at line 908 of file qfileinfo.cpp.

References d.

Referenced by QDirSortItem::QDirSortItem(), QAbstractFileIconEngine::cacheKey(), QWindowsFileIconEngine::cacheKey(), createReadHandlerHelper(), createWriteHandlerHelper(), QStandardPaths::findExecutable(), QGeoFileTileCache::getFromDisk(), QSSGAssetImportManager::getOptionsForFile(), QSSGInputUtil::getStreamForTextureFile(), hasSuffix(), QSSGAssetImportManager::importFile(), QExtendedInformation::isSymLink(), QMediaPlayerPrivate::setMedia(), QFileDialogPrivate::useNameFilter(), and QTextDocumentWriter::write().

+ Here is the caller graph for this function:

◆ swap()

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

Swaps this file info with other. This function is very fast and never fails.

Definition at line 60 of file qfileinfo.h.

References other().

+ Here is the call graph for this function:

◆ symLinkTarget()

QString QFileInfo::symLinkTarget ( ) const
Since
4.2

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

See also
exists(), isSymLink(), isDir(), isFile()

Definition at line 1289 of file qfileinfo.cpp.

References QAbstractFileEngine::AbsoluteLinkTarget, and d.

Referenced by QFileInfoGatherer::getInfo(), and QFile::symLinkTarget().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ comparesEqual

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

Definition at line 450 of file qfileinfo.cpp.

◆ QDirIteratorPrivate

friend class QDirIteratorPrivate
friend

Definition at line 24 of file qfileinfo.h.

◆ QDirListingPrivate

friend class QDirListingPrivate
friend

Definition at line 25 of file qfileinfo.h.

◆ QFileInfoList()

QFileInfoList
related

Synonym for QList<QFileInfo>.

Definition at line 189 of file qfileinfo.h.

Member Data Documentation

◆ d_ptr

QSharedDataPointer<QFileInfoPrivate> QFileInfo::d_ptr
protected

Definition at line 175 of file qfileinfo.h.

Referenced by makeAbsolute(), operator=(), and setFile().


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