Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QFileInfo Class Reference

\inmodule QtCore \reentrant More...

#include <qfileinfo.h>

+ Collaboration diagram for QFileInfo:

Public Member Functions

 QFileInfo (QFileInfoPrivate *d)
 
 QFileInfo ()
 Constructs an empty QFileInfo object.
 
QFILEINFO_MAYBE_EXPLICIT QFileInfo (const QString &file)
 Constructs a new QFileInfo that gives information about the given 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)
 Constructs a new QFileInfo that gives information about the given file relative to the directory dir.
 
 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
 
bool operator== (const QFileInfo &fileinfo) const
 Returns true if this QFileInfo object refers to a file in the same location as fileinfo; otherwise returns false.
 
bool operator!= (const QFileInfo &fileinfo) const
 Returns true if this QFileInfo object refers to a different file than the one specified by fileinfo; otherwise returns false.
 
void setFile (const QString &file)
 Sets the file that the QFileInfo provides information about to 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 file that the QFileInfo provides information about to file in directory dir.
 
bool exists () const
 Returns true if the file exists; otherwise returns false.
 
void refresh ()
 Refreshes the information about the file, i.e.
 
QString filePath () const
 Returns the file name, including the path (which may be absolute or relative).
 
QString absoluteFilePath () const
 Returns an absolute path including the file name.
 
QString canonicalFilePath () const
 Returns the canonical path including the file name, i.e.
 
QString fileName () const
 Returns the name of the file, excluding the path.
 
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 file's path.
 
QString absolutePath () const
 Returns a file's path absolute path.
 
QString canonicalPath () const
 Returns the file's path canonical path (excluding the file name), i.e.
 
QDir dir () const
 Returns the path of the object's parent directory as a QDir object.
 
QDir absoluteDir () const
 Returns the file's absolute path as a QDir object.
 
bool isReadable () const
 Returns true if the user can read the file; otherwise returns false.
 
bool isWritable () const
 Returns true if the user can write to the file; otherwise returns false.
 
bool isExecutable () const
 Returns true if the file is executable; otherwise returns false.
 
bool isHidden () const
 Returns true if this is a ‘hidden’ file; otherwise returns false.
 
bool isNativePath () const
 
bool isRelative () const
 Returns true if the file path is relative, otherwise returns false (i.e.
 
bool isAbsolute () const
 Returns true if the file path is absolute, otherwise returns false (i.e.
 
bool makeAbsolute ()
 Converts the file's path to an absolute path if it is not already in that form.
 
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
 Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.
 
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
 

Related Symbols

(Note that these are not member symbols.)

 QFileInfoList
 Synonym for QList<QFileInfo>.
 

Detailed Description

\inmodule QtCore \reentrant

The QFileInfo class provides system-independent file information.

QFileInfo provides information about a file's name and position (path) in the file system, its access rights and whether it is a directory or symbolic link, etc. The file'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 with either a relative or an absolute file path. Absolute file paths begin with the directory separator "/" (or with a drive specification on Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current working directory. An example of an absolute path is the string "/tmp/quartz". A relative path might look like "src/fatlib". You can use the function isRelative() to check whether a QFileInfo is using a relative or an absolute file path. You can call the function makeAbsolute() to convert a relative QFileInfo's path to an absolute path.

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

The file that the QFileInfo works on is set in the constructor or later with setFile(). Use exists() to see if the file exists and size() to get its size.

The file's type is obtained with isFile(), isDir() and isSymLink(). The symLinkTarget() function provides the name of the file the symlink points to.

Elements of the file's name can be extracted with path() and fileName(). The fileName()'s parts can be extracted with baseName(), suffix() or completeSuffix(). QFileInfo objects to directories created by Qt classes will not have a trailing file separator. If you wish to use trailing separators in your own file info objects, just append one to the file name 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.

Definition at line 21 of file qfileinfo.h.

Constructor & Destructor Documentation

◆ QFileInfo() [1/6]

QFileInfo::QFileInfo ( QFileInfoPrivate p)
explicit

Definition at line 336 of file qfileinfo.cpp.

◆ QFileInfo() [2/6]

QFileInfo::QFileInfo ( )

Constructs an empty QFileInfo object.

Note that an empty QFileInfo object contain no file reference.

See also
setFile()

Definition at line 347 of file qfileinfo.cpp.

Referenced by exists(), and setFile().

+ Here is the caller graph for this function:

◆ QFileInfo() [3/6]

QFileInfo::QFileInfo ( const QString file)

Constructs a new QFileInfo that gives information about the given file.

The file can also include an absolute or relative path.

See also
setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath()

Definition at line 357 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 370 of file qfileinfo.cpp.

◆ QFileInfo() [5/6]

QFileInfo::QFileInfo ( const QDir dir,
const QString file 
)

Constructs a new QFileInfo that gives information about the given file relative to the directory dir.

If dir has a relative path, the QFileInfo will also have a relative path.

If file is an absolute path, then the directory specified by dir will be disregarded.

See also
isRelative()

Definition at line 386 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 394 of file qfileinfo.cpp.

◆ ~QFileInfo()

QFileInfo::~QFileInfo ( )

Destroys the QFileInfo and frees its resources.

Definition at line 404 of file qfileinfo.cpp.

Member Function Documentation

◆ absoluteDir()

QDir QFileInfo::absoluteDir ( ) const

Returns the file's absolute path as a QDir object.

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

Definition at line 921 of file qfileinfo.cpp.

References absolutePath().

Referenced by changeInstallName(), createImageNode(), deployRPaths(), qRelocateResourceFile(), Viewer::saveImage(), and QFileDialog::selectFile().

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

◆ absoluteFilePath()

QString QFileInfo::absoluteFilePath ( ) const

Returns an absolute path including the file name.

The absolute path name consists of the full path and the file name. On Unix this will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'. QFileInfo will uppercase drive letters. Note that QDir does not do this. The code snippet below shows this.

QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
QString absoluteFilePath() const
Returns an absolute path including the file name.
QFileInfo fi("c:/temp/foo")
[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.
See also
filePath(), canonicalFilePath(), isRelative()

Definition at line 556 of file qfileinfo.cpp.

References QAbstractFileEngine::AbsoluteName, and d.

Referenced by QIconCacheGtkReader::QIconCacheGtkReader(), TestCaseCollector::TestCaseCollector(), _qt_get_directory(), QQmlTypeLoader::absoluteFilePath(), QFileDialog::accept(), QPixmapIconEngine::addFile(), QSvgIconEngine::addFile(), Parser::addIncludesRecursive(), QQmlJSLinter::applyFixes(), QDir::cd(), changeInstallName(), codesignBundle(), combinePath(), compilerRunTimeLibs(), deploy(), deployRPaths(), deployTranslations(), deployWebEngineCore(), QGtk3Interface::fileIcon(), fileType(), findFilesRecursively(), freeDesktopTrashLocation(), QConfFile::fromName(), QUrl::fromUserInput(), QFileInfoGatherer::getInfo(), handleCompileErrors(), QFileIconProvider::icon(), QGenericUnixTheme::iconFallbackPaths(), iconThemeSearchPaths(), QQmlPluginImporter::importDynamicPlugin(), QSSGAssetImportManager::importFile(), QQmlPluginImporter::importPlugins(), QFile::link(), QQmlJSLinter::lintFile(), QPixmap::load(), loadModelShapeMesh(), makeAbsolute(), parseArguments(), QRhiMetal::pipelineCacheData(), QFreeTypeFontDatabase::populateFontDatabase(), QAndroidPlatformFontDatabase::populateFontDatabase(), QSvgHandler::processingInstruction(), QQml_isFileCaseCorrect(), quick_test_main_with_setup(), QQmlDataBlob::SourceCodeData::readAll(), resolveBugListFile(), Parser::resolveInclude(), Viewer::saveImage(), scanImports(), QRhiMetal::setPipelineCacheData(), translateDriveName(), QAbstractFileIconProvider::type(), updateLibrary(), QQuickFileDialogImplPrivate::updateSelectedFile(), RCCFileInfo::writeDataBlob(), QQmlToolingSettings::writeDefaults(), and QGenericUnixTheme::xdgIconThemePaths().

◆ absolutePath()

QString QFileInfo::absolutePath ( ) const

Returns a file's path absolute path.

This doesn't include the file name.

On Unix the absolute path will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'.

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

References QAbstractFileEngine::AbsolutePathName, and d.

Referenced by _qt_get_directory(), absoluteDir(), Parser::addIncludesRecursive(), QTranslatorPrivate::do_load(), QZipReader::extractAll(), findFilesRecursively(), findMinGWRuntimePaths(), QQmlPluginImporter::importDynamicPlugin(), QCss::Parser::init(), QQmlDataTest::initTestCase(), QConfFile::isWritable(), QTextDocument::loadResource(), parseArguments(), readInputFile(), QTextBrowserPrivate::resolveUrl(), scanImports(), QTest::setMainSourcePath(), updateFile(), 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"
QString baseName() const
Returns the base name of the file without the path.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127

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

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

Referenced by detectLatestAndroidPlatform(), handleCompileErrors(), Driver::headerFileName(), QDeferredFactory< QQmlJSScope >::internalName(), QQmlJSTypeReader::operator()(), parseProvider(), qQmlJSSymbolNamespaceForPath(), quasiLexicographicalReverseLessThan(), quick_test_main_with_setup(), QImageReader::read(), Viewer::saveImage(), and QQmlJS::Dom::QQmlDomAstCreator::visit().

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

If the file is a symlink, the time of the target file is returned (not the 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 154 of file qfileinfo.h.

References QFileDevice::FileBirthTime.

Referenced by QNetworkDiskCache::expire().

+ Here is the caller graph for this function:

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

If the file is a symlink, the time of the target file is returned (not the symlink).

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

Definition at line 160 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"
QString bundleName() const
QString bundle
See also
isBundle(), filePath(), baseName(), suffix()

Definition at line 793 of file qfileinfo.cpp.

References QAbstractFileEngine::BundleName, and d.

Referenced by checkExecutable().

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

References d.

Referenced by setFile().

+ Here is the caller graph for this function:

◆ canonicalFilePath()

◆ canonicalPath()

QString QFileInfo::canonicalPath ( ) const

Returns the file's path canonical path (excluding the file name), i.e.

an absolute path without symbolic links or redundant "." or ".." elements.

If the file does not exist, canonicalPath() returns an empty string.

See also
path(), absolutePath()

Definition at line 616 of file qfileinfo.cpp.

References QAbstractFileEngine::CanonicalPathName, and d.

Referenced by changeInstallName(), QQmlJSImportVisitor::implicitImportDirectory(), QQmlJSAotCompiler::setDocument(), and QQmlJS::Dom::QQmlDomAstCreator::visit().

+ 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"
QString completeBaseName() const
Returns the complete base name of the file without the path.
See also
fileName(), suffix(), completeSuffix(), baseName()

Definition at line 838 of file qfileinfo.cpp.

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

Referenced by AssimpImporter::import(), moc(), and qtResourceNameForFile().

+ 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"
QString completeSuffix() const
Returns the complete suffix (extension) of the file.
See also
fileName(), suffix(), baseName(), completeBaseName()

Definition at line 860 of file qfileinfo.cpp.

References d.

Referenced by QLibrary::isLibrary(), QPixmap::load(), QV4::ExecutableCompilationUnit::localCacheFilePath(), MainWindow::openFile(), QQuickNinePatchImage::pixmapChange(), and qQmlJSSymbolNamespaceForPath().

+ Here is the caller graph for this function:

◆ dir()

QDir QFileInfo::dir ( ) const

Returns the path of the object's parent directory as a QDir object.

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

References d.

Referenced by combinePath(), QNetworkAccessFileBackendFactory::create(), main(), QQmlLocalStorage::openDatabaseSync(), Moc::parsePluginData(), quick_test_main_with_setup(), QQmlToolingSettings::search(), setFile(), and QQuickFileDialogImpl::setInitialCurrentFolderAndSelectedFile().

+ Here is the caller graph for this function:

◆ exists() [1/2]

bool QFileInfo::exists ( ) const

Returns true if the file exists; otherwise returns false.

Note
If the file is a symlink that points to a non-existing file, false is returned.

Definition at line 696 of file qfileinfo.cpp.

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

Referenced by QIconCacheGtkReader::QIconCacheGtkReader(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QSSGShaderCache::QSSGShaderCache(), QFileDialogPrivate::_q_pathChanged(), _qt_get_directory(), QFileDialog::accept(), Parser::addIncludesRecursive(), QPollingFileSystemWatcherEngine::addPaths(), checkNeedPortalSupport(), checkNeedPortalSupport(), copyAndroidExtraLibs(), copyAndroidExtraResources(), copyDylib(), QSSGQmlUtilities::copyTextureAsset(), QNetworkAccessFileBackendFactory::create(), createDirectory(), deployWebEngineCore(), QQmlTypeLoader::directoryExists(), existingImageFileForPath(), QFile::exists(), QDir::exists(), QFileSystemModel::filePath(), findFilesRecursively(), findFilesRecursively(), findInPath(), QUrl::fromUserInput(), QFileInfoGatherer::getInfo(), getLibraryProjectsInOutputFolder(), QSSGAssetImportManager::getOptionsForFile(), QSSGInputUtil::getStreamForFile(), iconTempPath(), QSSGAssetImportManager::importFile(), importImp(), QConfFile::isWritable(), QPixmap::load(), loadModelShapeMesh(), QTextDocument::loadResource(), AndroidStyle::loadStyleData(), QDirIteratorPrivate::matchesFilters(), QFileSystemModelPrivate::node(), QSaveFile::open(), parseArguments(), parseEarlyArguments(), Moc::parsePluginData(), QSvgHandler::processingInstruction(), QTest::qFindTestData(), quick_test_main_with_setup(), Preprocessor::resolveInclude(), Parser::resolveInclude(), QTextBrowserPrivate::resolveUrl(), QWindowsFileSystemWatcherEngineThread::run(), QDBusXmlToCpp::run(), scanImports(), searchIncludePaths(), QQuickFolderListModel::setFolder(), QQuickFolderListModel::setRootFolder(), QFileSystemModel::setRootPath(), QExtendedInformation::size(), QQuickFolderBreadcrumbBarPrivate::textFieldAccepted(), QExtendedInformation::type(), updateFile(), and updateFile().

+ Here is the call graph for this function:

◆ exists() [2/2]

bool QFileInfo::exists ( const QString file)
static
Since
5.2

Returns true if the file exists; otherwise returns false.

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

Definition at line 720 of file qfileinfo.cpp.

References QFileInfo(), engine, QFileSystemMetaData::ExistsAttribute, file, QFileSystemEngine::fillMetaData(), and QFileSystemEngine::resolveEntryAndCreateLegacyEngine().

+ Here is the call graph for this function:

◆ fileName()

QString QFileInfo::fileName ( ) const

Returns the name of the file, excluding the path.

Example:

QFileInfo fi("/tmp/archive.tar.gz");
QString name = fi.fileName(); // name = "archive.tar.gz"
QString fileName() const
Returns the name of the file, excluding the path.
GLuint name

Note that, if this QFileInfo object is given a path ending in a slash, the name of the file is considered empty.

See also
isRelative(), filePath(), baseName(), suffix()

Definition at line 771 of file qfileinfo.cpp.

References QAbstractFileEngine::BaseName, and d.

Referenced by QFileDialogArgs::QFileDialogArgs(), QFileDialogPrivate::_q_updateOkButton(), QFileDialog::accept(), QFileDialogPrivate::addDefaultSuffixToFiles(), Parser::addIncludesRecursive(), QAbstractFileIconEngine::cacheKey(), QWindowsFileIconEngine::cacheKey(), QTextureFileReader::canRead(), changeInstallName(), QDirIteratorPrivate::checkAndPushDirectory(), copyAndroidExtraLibs(), QSSGQmlUtilities::copyTextureAsset(), QWindowsFileDialogHelper::createNativeDialog(), QFSFileEngineIterator::currentFileName(), deploy(), deployWebEngineCore(), QAndroidStyle::AndroidImageDrawable::draw(), QAndroidStyle::Android9PatchDrawable::draw(), QNetworkDiskCache::expire(), QDirIterator::fileName(), QEglFSDeviceIntegration::framebufferIndex(), QFileInfoGatherer::getInfo(), QBenchmarkValgrindUtils::getNewestFileName(), QLockFilePrivate::isProcessRunning(), main(), moc(), QQmlLocalStorage::openDatabaseSync(), QDirSortItemComparator::operator()(), patchQtCore(), qtResourceNameForFile(), QNetworkDiskCachePrivate::removeFile(), retrieveLabel(), QFileSelectorPrivate::select(), QQmlJSAotCompiler::setDocument(), QQuickImageSelector::setUrl(), sm_performSaveYourself(), QDirPrivate::sortFileList(), JsonOutput::toList(), translateDriveName(), updateFile(), updateFile(), updateLibsXml(), QWidget::windowTitle(), writeEtw(), and writeLttng().

+ Here is the caller graph for this function:

◆ filePath()

◆ fileTime() [1/2]

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

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

If the file is a symlink, the time of the target file is returned
(not the symlink).

\since 6.6
\sa birthTime(const QTimeZone &), lastModified(const QTimeZone &), lastRead(const QTimeZone &), metadataChangeTime(const QTimeZone &), QDateTime::isValid()

Definition at line 1641 of file qfileinfo.cpp.

References QAbstractFileEngine::AccessTime, QFileSystemMetaData::AccessTime, QAbstractFileEngine::BirthTime, QFileSystemMetaData::BirthTime, d, QFileDevice::FileAccessTime, QFileDevice::FileBirthTime, QFileDevice::FileMetadataChangeTime, QFileDevice::FileModificationTime, QAbstractFileEngine::MetadataChangeTime, QFileSystemMetaData::MetadataChangeTime, QAbstractFileEngine::ModificationTime, 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).

If the file is a symlink, this function returns the owning group of the target (not the symlink).

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

Definition at line 1362 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.

If the file is a symlink, this function returns the id of the group owning the target (not the symlink).

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

Definition at line 1381 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 path is absolute, otherwise returns false (i.e.

the path is relative).

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

Definition at line 116 of file qfileinfo.h.

References isRelative().

Referenced by _qt_get_directory(), QFileDialogPrivate::addDefaultSuffixToFiles(), QTextDocument::loadResource(), QTest::qFindTestData(), 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 1189 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.

If the file is a symlink, this function returns true if the target is a bundle (not the symlink).

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

Definition at line 1077 of file qfileinfo.cpp.

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

Referenced by checkExecutable().

+ Here is the caller graph for this function:

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

If the file is a symlink, this function returns true if the target is a directory (not the symlink).

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

Definition at line 1057 of file qfileinfo.cpp.

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

Referenced by QFileDialogArgs::QFileDialogArgs(), QIconTheme::QIconTheme(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QFileDialogPrivate::_q_updateOkButton(), _qt_get_directory(), QFileDialog::accept(), QFileDialogPrivate::addDefaultSuffixToFiles(), QInotifyFileSystemWatcherEngine::addPaths(), QPollingFileSystemWatcherEngine::addPaths(), QDirIteratorPrivate::checkAndPushDirectory(), QQuickFileDialogDelegatePrivate::chooseFile(), copyAndroidExtraResources(), createDirectory(), QWindowsFileDialogHelper::createNativeDialog(), deployWebEngineCore(), QQmlTypeLoader::directoryExists(), QZipReader::extractAll(), QWindowsFileIconEngine::filePixmap(), findFilesRecursively(), freeDesktopTrashLocation(), QAbstractFileIconProviderPrivate::getIconThemeIcon(), getLibraryProjectsInOutputFolder(), QQuickFileDialogImplPrivate::handleClick(), QFileIconProvider::icon(), QGenericUnixTheme::iconFallbackPaths(), iconThemeSearchPaths(), QFileSystemModelPrivate::QFileSystemNode::isDir(), QFileSystemModel::isDir(), loadTzTimeZones(), QDirIteratorPrivate::matchesFilters(), QMimeDatabasePrivate::mimeTypeForFile(), QFileSystemEngine::moveFileToTrash(), QNetworkFile::open(), QSaveFile::open(), QDirSortItemComparator::operator()(), parseArguments(), Moc::parsePluginData(), quick_test_main_with_setup(), QFseventsFileSystemWatcherEngine::removePaths(), QDir::removeRecursively(), Preprocessor::resolveInclude(), QQmlToolingSettings::search(), searchIncludePaths(), QQuickFolderListModel::setFolder(), QQuickFolderListModel::setRootFolder(), QFileSystemModelPrivate::QFileSystemNode::size(), QQuickFolderBreadcrumbBarPrivate::textFieldAccepted(), QExtendedInformation::type(), QAbstractFileIconProvider::type(), updateFile(), updateFile(), vcRedistDir(), and QGenericUnixTheme::xdgIconThemePaths().

◆ isExecutable()

bool QFileInfo::isExecutable ( ) const

Returns true if the file is executable; otherwise returns false.

If the file is a symlink, this function returns true if the target is executable (not the symlink).

See also
isReadable(), isWritable(), permission()

Definition at line 974 of file qfileinfo.cpp.

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

Referenced by bluetoothdVersion(), QAbstractFileIconEngine::cacheKey(), checkExecutable(), findInPath(), QDirIteratorPrivate::matchesFilters(), and parseEarlyArguments().

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

If the file is a symlink, this function returns true if the target is a regular file (not the symlink).

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

Definition at line 1037 of file qfileinfo.cpp.

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

Referenced by QQmlTypeLoader::absoluteFilePath(), QAbstractFileIconEngine::cacheKey(), checkExecutable(), compilerRunTimeLibs(), deploy(), existsAsSpecified(), QZipReader::extractAll(), findInPath(), QFileInfoGatherer::getInfo(), QFileIconProvider::icon(), is_readable_file(), QFileSystemModelPrivate::QFileSystemNode::isFile(), QTranslator::load(), QQmlJS::Dom::DomEnvironment::loadBuiltins(), QQmlJS::Dom::DomEnvironment::loadModuleDependency(), loadTzTimeZones(), QDirIteratorPrivate::matchesFilters(), QmlDirectoryFileEntryFunction::operator()(), parseArguments(), QQmlJS::Dom::ModuleIndex::qmldirsToLoad(), quick_test_main_with_setup(), QFileSystemModel::remove(), resolveBugListFile(), QDBusXmlToCpp::run(), QExtendedInformation::type(), QAbstractFileIconProvider::type(), and updateLibrary().

+ Here is the caller graph for this function:

◆ isHidden()

bool QFileInfo::isHidden ( ) const

Returns true if this is a ‘hidden’ file; otherwise returns false.

{Note:} This function returns true for the special entries "." and ".." on Unix, even though QDir::entryList threats 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 994 of file qfileinfo.cpp.

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

Referenced by QDirIteratorPrivate::checkAndPushDirectory(), QExtendedInformation::isHidden(), QFileSystemModelPrivate::QFileSystemNode::isHidden(), and QDirIteratorPrivate::matchesFilters().

+ 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 1209 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 1016 of file qfileinfo.cpp.

References d, and QAbstractFileEngine::LocalDiskFlag.

Referenced by QSSGInputUtil::getStreamForFile(), and QMimeDatabasePrivate::mimeTypeForFile().

+ Here is the caller graph for this function:

◆ isReadable()

bool QFileInfo::isReadable ( ) const

Returns true if the user can read the file; otherwise returns false.

If the file is a symlink, this function returns true if the target is readable (not the symlink).

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

Definition at line 937 of file qfileinfo.cpp.

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

Referenced by QTextBrowserPrivate::findFile(), QFileInfoGatherer::getInfo(), is_readable_file(), QTranslator::load(), QDirIteratorPrivate::matchesFilters(), and QDBusXmlToCpp::run().

+ Here is the caller graph for this function:

◆ isRelative()

bool QFileInfo::isRelative ( ) const

Returns true if the file path is relative, otherwise returns false (i.e.

the path is absolute). (E.g. under Unix a path is absolute if it begins with a "/").

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

Definition at line 663 of file qfileinfo.cpp.

References d.

Referenced by QSSGQmlUtilities::copyTextureAsset(), 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 1223 of file qfileinfo.cpp.

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

Referenced by QWindowsFileIconEngine::filePixmap(), and QAbstractFileIconProviderPrivate::getIconThemeIcon().

+ 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 1165 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.

Note
If the symlink points to a non existing file, exists() returns false.
See also
isFile(), isDir(), isShortcut(), symLinkTarget()

Definition at line 1139 of file qfileinfo.cpp.

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

◆ isSymLink()

bool QFileInfo::isSymLink ( ) const

Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.

Symbolic links exist on Unix (including \macos and iOS) and Windows and are typically created by the {ln -s} or {mklink} commands, respectively. Opening a symbolic link effectively opens the \l{symLinkTarget()}{link's target}.

In addition, true will be returned for shortcuts (*.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 .lnk or alias file itself.

Example:

bool isSymLink() const
Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.
QString symLinkTarget() const
QFileInfo info(fileName)
[8]
Note
If the symlink points to a non existing file, exists() returns false.
See also
isFile(), isDir(), symLinkTarget()

Definition at line 1109 of file qfileinfo.cpp.

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

Referenced by QFileDialogPrivate::_q_deleteCurrent(), QAbstractFileIconEngine::cacheKey(), QDirIteratorPrivate::checkAndPushDirectory(), QZipReader::extractAll(), QEglFSDeviceIntegration::framebufferIndex(), freeDesktopTrashLocation(), QFileInfoGatherer::getInfo(), QFileIconProvider::icon(), QLockFilePrivate::isProcessRunning(), QExtendedInformation::isSymLink(), QFileSystemModelPrivate::QFileSystemNode::isSymLink(), loadTzTimeZones(), QDirIteratorPrivate::matchesFilters(), QSaveFile::open(), QDirIteratorPrivate::pushDirectory(), QFileSystemModel::remove(), QDir::removeRecursively(), retrieveLabel(), runningUnderDebugger(), QExtendedInformation::size(), QExtendedInformation::type(), QAbstractFileIconProvider::type(), updateFile(), and updateFile().

+ Here is the caller graph for this function:

◆ isWritable()

bool QFileInfo::isWritable ( ) const

Returns true if the user can write to the file; otherwise returns false.

If the file is a symlink, this function returns true if the target is writeable (not the symlink).

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

Definition at line 957 of file qfileinfo.cpp.

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

Referenced by ensureWritableDir(), ensureWritableDir(), QDirIteratorPrivate::matchesFilters(), QSaveFile::open(), 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 1299 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.

If the file is a symlink, the time of the target file is returned (not the 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 156 of file qfileinfo.h.

References QFileDevice::FileModificationTime.

Referenced by QIconCacheGtkReader::QIconCacheGtkReader(), QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QV4::ExecutionEngine::compileModule(), copyFileIfNewer(), QGeoFileTileCacheOsm::init(), QLockFilePrivate::isApparentlyStale(), QExtendedInformation::lastModified(), QFileSystemModelPrivate::QFileSystemNode::lastModified(), QMimeBinaryProvider::CacheFile::load(), QPixmap::load(), QNetworkFile::open(), QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), QDirSortItemComparator::operator()(), QWindowsFileSystemWatcherEngine::PathInfo::operator=(), QExtendedInformation::operator==(), QLockFile::tryLock(), updateFile(), updateFile(), QV4::ExecutableCompilationUnit::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

If the file is a symlink, the time of the target file is returned (not the symlink).

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

Definition at line 162 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().

If the file is a symlink, the time of the target file is returned (not the 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 157 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().

If the file is a symlink, the time of the target file is returned (not the symlink).

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

Definition at line 163 of file qfileinfo.h.

References QFileDevice::FileAccessTime.

◆ makeAbsolute()

bool QFileInfo::makeAbsolute ( )

Converts the file's path to an absolute path if it is not already in that form.

Returns true to indicate that the path was converted; otherwise returns false to indicate that the path was already absolute.

See also
filePath(), isRelative()

Definition at line 680 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).

If the file is a symlink, the time of the target file is returned (not the 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 155 of file qfileinfo.h.

References QFileDevice::FileMetadataChangeTime.

Referenced by QNetworkDiskCache::expire().

+ Here is the caller graph for this function:

◆ 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

If the file is a symlink, the time of the target file is returned (not the symlink).

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

Definition at line 161 of file qfileinfo.h.

References QFileDevice::FileMetadataChangeTime.

◆ operator!=()

bool QFileInfo::operator!= ( const QFileInfo fileinfo) const
inline

Returns true if this QFileInfo object refers to a different file than the one specified by fileinfo; otherwise returns false.

See also
operator==()

Definition at line 62 of file qfileinfo.h.

References operator==().

+ Here is the call graph for this function:

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

Since
5.2

Definition at line 466 of file qfileinfo.cpp.

References d_ptr.

◆ operator==()

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

Returns true if this QFileInfo object refers to a file in the same location as fileinfo; otherwise returns false.

Note that the result of comparing two empty QFileInfo objects, containing no file references (file paths that do not exist or are empty), is undefined.

Warning
This will not compare two different symbolic links pointing to the same file.
Long and short file names that refer to the same file on Windows are treated as if they referred to different files.
See also
operator!=()

Definition at line 433 of file qfileinfo.cpp.

References canonicalFilePath(), Qt::CaseInsensitive, Qt::CaseSensitive, QString::compare(), d, d_ptr, QFileInfoPrivate::fileEngine, QFileInfoPrivate::fileEntry, QFileSystemEntry::filePath(), QFileSystemEngine::isCaseSensitive(), and QFileInfoPrivate::isDefaultConstructed.

+ Here is the call graph for this function:

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

If the file is a symlink, this function returns the owner of the target (not the symlink).

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

Definition at line 1321 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).

If the file is a symlink, this function returns the id of the owner of the target (not the symlink).

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

Definition at line 1340 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 file's path.

This doesn't include the file name.

Note that, if this QFileInfo object is given a path ending in a slash, the name of the file is considered empty and this function will return the entire path.

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

Definition at line 633 of file qfileinfo.cpp.

References d.

Referenced by QFileDialog::accept(), QFseventsFileSystemWatcherEngine::addPaths(), QCoreApplication::applicationDirPath(), QPainter::clipBoundingRect(), QPainter::clipRegion(), deployPlugins(), operator<<(), qQmlJSSymbolNamespaceForPath(), QWasmIDBSettingsPrivate_onLoad(), RCCResourceLibrary::readFiles(), QFseventsFileSystemWatcherEngine::removePaths(), QPaintEngineExPrivate::replayClipOperations(), QPainter::restore(), QFileSelectorPrivate::select(), QQuickImageSelector::setUrl(), and QQmlApplicationEnginePrivate::startLoad().

+ 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");
qWarning("I can change the file; my group can read the file");
qWarning("The group or others can change the file");
bool permission(QFile::Permissions permissions) const
Tests for file permissions.
#define qWarning
Definition qlogging.h:162

If the file is a symlink, this function checks the permissions of the target (not the symlink).

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

Definition at line 1409 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.

If the file is a symlink, this function returns the permissions of the target (not the symlink).

Definition at line 1433 of file qfileinfo.cpp.

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

Referenced by QZipReader::extractAll(), QSaveFile::open(), QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), QWindowsFileSystemWatcherEngine::PathInfo::operator=(), QExtendedInformation::operator==(), permission(), QExtendedInformation::permissions(), and QFileSystemModelPrivate::QFileSystemNode::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 1277 of file qfileinfo.cpp.

References d, and QAbstractFileEngine::RawLinkPath.

◆ refresh()

void QFileInfo::refresh ( )

Refreshes the information about the file, i.e.

reads in information from the file system the next time a cached property is fetched.

Definition at line 740 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 1703 of file qfileinfo.cpp.

References d.

◆ setFile() [1/3]

void QFileInfo::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 file that the QFileInfo provides information about to file in directory dir.

If file includes a relative path, the QFileInfo will also have a relative path.

See also
isRelative()

Definition at line 529 of file qfileinfo.cpp.

References dir(), file, 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 513 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 file)

Sets the file that the QFileInfo provides information about to file.

The file can also include an absolute or relative file path. Absolute paths begin with the directory separator (e.g. "/" under Unix) or a drive specification (under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory.

Example:

QFileInfo info("/usr/bin/env");
QString path = info.absolutePath(); // path = /usr/bin
QString base = info.baseName(); // base = env
info.setFile("/etc/hosts");
path = info.absolutePath(); // path = /etc
base = info.baseName(); // base = hosts
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
QString absolutePath() const
Returns a file's path absolute path.
GLsizei const GLchar *const * path
See also
isRelative(), QDir::setCurrent(), QDir::isRelativePath()

Definition at line 495 of file qfileinfo.cpp.

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

Referenced by compilerRunTimeLibs(), QAbstractFileEngineIterator::currentFileInfo(), QSSGInputUtil::getStreamForFile(), QLockFilePrivate::isProcessRunning(), QTranslator::load(), makeAbsolute(), QSaveFile::open(), Moc::parsePluginData(), QTest::qFindTestData(), Preprocessor::resolveInclude(), searchIncludePaths(), setFile(), setFile(), and QTest::setMainSourcePath().

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

◆ size()

◆ 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 1719 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"
QString suffix() const
Returns the suffix (extension) of the file.

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

References d.

Referenced by QDirSortItem::QDirSortItem(), QFileDialogPrivate::_q_useNameFilter(), QIcon::addFile(), QQmlJSLinter::applyFixes(), QAbstractFileIconEngine::cacheKey(), QWindowsFileIconEngine::cacheKey(), QTextureFileReader::canRead(), copyAndroidExtraLibs(), createReadHandlerHelper(), createWriteHandlerHelper(), existingImageFileForPath(), QStandardPaths::findExecutable(), QGeoFileTileCache::getFromDisk(), QSSGAssetImportManager::getOptionsForFile(), QSSGInputUtil::getStreamForTextureFile(), hasSuffix(), QSSGAssetImportManager::importFile(), QExtendedInformation::isSymLink(), QQmlJSLinter::lintFile(), moc(), QQmlJSTypeReader::operator()(), QMediaPlayerPrivate::setMedia(), QPrinter::setOutputFileName(), 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 58 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. QFileInfo::exists() returns true if the symlink points to an existing file.

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

Definition at line 1258 of file qfileinfo.cpp.

References QAbstractFileEngine::AbsoluteLinkTarget, and d.

Referenced by QEglFSDeviceIntegration::framebufferIndex(), freeDesktopTrashLocation(), QFileInfoGatherer::getInfo(), QLockFilePrivate::isProcessRunning(), QSaveFile::open(), retrieveLabel(), runningUnderDebugger(), QFile::symLinkTarget(), and updateFile().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QDirIteratorPrivate

friend class QDirIteratorPrivate
friend

Definition at line 23 of file qfileinfo.h.

◆ QFileInfoList()

QFileInfoList
related

Synonym for QList<QFileInfo>.

Definition at line 183 of file qfileinfo.h.

Member Data Documentation

◆ d_ptr

QSharedDataPointer<QFileInfoPrivate> QFileInfo::d_ptr
protected

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