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>.
|
#include <qfileinfo.h>
Public Member Functions | |
QFileInfo (QFileInfoPrivate *d) | |
QFileInfo () | |
Constructs an empty QFileInfo object that doesn't refer to any file system entry. | |
QFILEINFO_MAYBE_EXPLICIT | QFileInfo (const QString &file) |
QFILEINFO_MAYBE_EXPLICIT | QFileInfo (const QFileDevice &file) |
Constructs a new QFileInfo that gives information about file file. | |
QFILEINFO_MAYBE_EXPLICIT | QFileInfo (const QDir &dir, const QString &file) |
QFileInfo (const QFileInfo &fileinfo) | |
Constructs a new QFileInfo that is a copy of the given fileinfo. | |
~QFileInfo () | |
Destroys the QFileInfo and frees its resources. | |
QFileInfo & | operator= (const QFileInfo &fileinfo) |
Move-assigns other to this QFileInfo instance. | |
void | swap (QFileInfo &other) noexcept |
void | setFile (const QString &file) |
void | setFile (const QFileDevice &file) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the file that the QFileInfo provides information about to file. | |
void | setFile (const QDir &dir, const QString &file) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the path of the file system entry that this QFileInfo provides information about to path in directory dir. | |
bool | exists () const |
Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false . | |
void | refresh () |
Refreshes the information about the file system entry this QFileInfo refers to, that is, reads in information from the file system the next time a cached property is fetched. | |
QString | filePath () const |
Returns the path of the file system entry this QFileInfo refers to; the path may be absolute or relative. | |
QString | absoluteFilePath () const |
QString | canonicalFilePath () const |
Returns the file system entry's canonical path, including the entry's name, that is, an absolute path without symbolic links or redundant {'.'} or {'..'} elements. | |
QString | fileName () const |
QString | baseName () const |
Returns the base name of the file without the path. | |
QString | completeBaseName () const |
Returns the complete base name of the file without the path. | |
QString | suffix () const |
Returns the suffix (extension) of the file. | |
QString | bundleName () const |
QString | completeSuffix () const |
Returns the complete suffix (extension) of the file. | |
QString | path () const |
Returns the path of the file system entry this QFileInfo refers to, excluding the entry's name. | |
QString | absolutePath () const |
Returns the absolute path of the file system entry this QFileInfo refers to, excluding the entry's name. | |
QString | canonicalPath () const |
Returns the file system entry's canonical path (excluding the entry's name), i.e. | |
QDir | dir () const |
Returns a QDir object representing the path of the parent directory of the file system entry that this QFileInfo refers to. | |
QDir | absoluteDir () const |
Returns a QDir object representing the absolute path of the parent directory of the file system entry that this QFileInfo refers to. | |
bool | isReadable () const |
Returns true if the user can read the file system entry this QFileInfo refers to; otherwise returns false . | |
bool | isWritable () const |
Returns true if the user can write to the file system entry this QFileInfo refers to; otherwise returns false . | |
bool | isExecutable () const |
bool | isHidden () const |
Returns true if the file system entry this QFileInfo refers to is ‘hidden’; otherwise returns false . | |
bool | isNativePath () const |
bool | isRelative () const |
Returns true if the file system entry's path is relative, otherwise returns false (that is, the path is absolute). | |
bool | isAbsolute () const |
Returns true if the file system entry's path is absolute, otherwise returns false (that is, the path is relative). | |
bool | makeAbsolute () |
If the file system entry's path is relative, this method converts it to an absolute path and returns true ; if the path is already absolute, this method returns false . | |
bool | isFile () const |
Returns true if this object points to a file or to a symbolic link to a file. | |
bool | isDir () const |
Returns true if this object points to a directory or to a symbolic link to a directory. | |
bool | isSymLink () const |
bool | isSymbolicLink () const |
Returns true if this object points to a symbolic link; otherwise returns false . | |
bool | isShortcut () const |
Returns true if this object points to a shortcut; otherwise returns false . | |
bool | isAlias () const |
Returns true if this object points to an alias; otherwise returns false . | |
bool | isJunction () const |
bool | isRoot () const |
Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false . | |
bool | isBundle () const |
QString | symLinkTarget () const |
QString | readSymLink () const |
QString | junctionTarget () const |
QString | owner () const |
Returns the owner of the file. | |
uint | ownerId () const |
Returns the id of the owner of the file. | |
QString | group () const |
Returns the group of the file. | |
uint | groupId () const |
Returns the id of the group the file belongs to. | |
bool | permission (QFile::Permissions permissions) const |
Tests for file permissions. | |
QFile::Permissions | permissions () const |
Returns the complete OR-ed together combination of QFile::Permissions for the file. | |
qint64 | size () const |
Returns the file size in bytes. | |
QDateTime | birthTime () const |
Returns the date and time when the file was created (born), in local time. | |
QDateTime | metadataChangeTime () const |
Returns the date and time when the file's metadata was last changed, in local time. | |
QDateTime | lastModified () const |
Returns the date and time when the file was last modified. | |
QDateTime | lastRead () const |
Returns the date and time when the file was last read (accessed). | |
QDateTime | fileTime (QFile::FileTime time) const |
QDateTime | birthTime (const QTimeZone &tz) const |
Returns the date and time when the file was created (born). | |
QDateTime | metadataChangeTime (const QTimeZone &tz) const |
Returns the date and time when the file's metadata was last changed. | |
QDateTime | lastModified (const QTimeZone &tz) const |
Returns the date and time when the file was last modified. | |
QDateTime | lastRead (const QTimeZone &tz) const |
Returns the date and time when the file was last read (accessed). | |
QDateTime | fileTime (QFile::FileTime time, const QTimeZone &tz) const |
bool | caching () const |
Returns true if caching is enabled; otherwise returns false . | |
void | setCaching (bool on) |
If enable is true, enables caching of file information. | |
void | stat () |
Reads all attributes from the file system. | |
Static Public Member Functions | |
static bool | exists (const QString &file) |
Protected Attributes | |
QSharedDataPointer< QFileInfoPrivate > | d_ptr |
Friends | |
class | QDirIteratorPrivate |
class | QDirListingPrivate |
Q_CORE_EXPORT bool | comparesEqual (const QFileInfo &lhs, const QFileInfo &rhs) |
Related Symbols | |
(Note that these are not member symbols.) | |
QFileInfoList | |
Synonym for QList<QFileInfo>. | |
Definition at line 22 of file qfileinfo.h.
|
explicit |
Definition at line 346 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | ) |
QFileInfo::QFileInfo | ( | const QString & | path | ) |
Constructs a QFileInfo that gives information about a file system entry located at \a path that can be absolute or relative.
! [preserve-relative-path] If path is relative, the QFileInfo will also have a relative path. ! [preserve-relative-path]
\sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath()
Definition at line 370 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | const QFileDevice & | file | ) |
Constructs a new QFileInfo that gives information about file file.
If the file has a relative path, the QFileInfo will also have a relative path.
Definition at line 383 of file qfileinfo.cpp.
Constructs a new QFileInfo that gives information about the given file system entry \a path that is relative to the directory \a dir.
! [preserve-relative-or-absolute] If dir has a relative path, the QFileInfo will also have a relative path.
If path is absolute, then the directory specified by dir will be disregarded. ! [preserve-relative-or-absolute]
\sa isRelative()
Definition at line 401 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | const QFileInfo & | fileinfo | ) |
Constructs a new QFileInfo that is a copy of the given fileinfo.
Definition at line 409 of file qfileinfo.cpp.
QFileInfo::~QFileInfo | ( | ) |
Destroys the QFileInfo and frees its resources.
Definition at line 419 of file qfileinfo.cpp.
QDir QFileInfo::absoluteDir | ( | ) | const |
Returns a QDir object representing the absolute path of the parent directory of the file system entry that this QFileInfo refers to.
Definition at line 950 of file qfileinfo.cpp.
References absolutePath().
Referenced by changeInstallName(), deployRPaths(), and qRelocateResourceFile().
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().
QString QFileInfo::absolutePath | ( | ) | const |
Returns the absolute path of the file system entry this QFileInfo refers to, excluding the entry's name.
absolute-path-unix-windows
windows-network-shares
In contrast to canonicalPath() symbolic links or redundant "." or ".." elements are not necessarily removed.
Definition at line 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().
QString QFileInfo::baseName | ( | ) | const |
Returns the base name of the file without the path.
The base name consists of all characters in the file up to (but not including) the first '.' character.
Example:
The base name of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").
Definition at line 842 of file qfileinfo.cpp.
References QAbstractFileEngine::BaseName, QFileSystemEntry::baseName(), and d.
Referenced by detectLatestAndroidPlatform(), QDeferredFactory< QQmlJSScope >::internalName(), parseProvider(), and QImageReader::read().
|
inline |
Returns the date and time when the file was created (born), in local time.
If the file birth time is not available, this function returns an invalid QDateTime.
info-about-target-not-symlink
This function overloads QFileInfo::birthTime(const QTimeZone &tz), and returns the same as {birthTime(QTimeZone::LocalTime)}.
Definition at line 158 of file qfileinfo.h.
References QFileDevice::FileBirthTime.
Returns the date and time when the file was created (born).
file-times-in-time-zone
If the file birth time is not available, this function returns an invalid QDateTime.
info-about-target-not-symlink
Definition at line 164 of file qfileinfo.h.
References QFileDevice::FileBirthTime.
QString QFileInfo::bundleName | ( | ) | const |
On \macos and iOS this returns the proper localized name for a bundle if the path isBundle(). On all other platforms an empty QString is returned.
Example:
Definition at line 818 of file qfileinfo.cpp.
References QAbstractFileEngine::BundleName, and d.
Referenced by QDirEntryInfo::bundleName().
bool QFileInfo::caching | ( | ) | const |
Returns true
if caching is enabled; otherwise returns false
.
Definition at line 1705 of file qfileinfo.cpp.
References d.
Referenced by setFile().
QString QFileInfo::canonicalFilePath | ( | ) | const |
Returns the file system entry's canonical path, including the entry's name, that is, an absolute path without symbolic links or redundant {'.'} or
{'..'} elements.
If the entry does not exist, canonicalFilePath() returns an empty string.
Definition at line 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().
QString QFileInfo::canonicalPath | ( | ) | const |
Returns the file system entry's canonical path (excluding the entry's name), i.e.
an absolute path without symbolic links or redundant "." or ".." elements.
If the entry does not exist, this method returns an empty string.
Definition at line 638 of file qfileinfo.cpp.
References QAbstractFileEngine::CanonicalPathName, and d.
Referenced by changeInstallName(), and QQmlJSImportVisitor::implicitImportDirectory().
QString QFileInfo::completeBaseName | ( | ) | const |
Returns the complete base name of the file without the path.
The complete base name consists of all characters in the file up to (but not including) the last '.' character.
Example:
Definition at line 863 of file qfileinfo.cpp.
References QAbstractFileEngine::BaseName, QFileSystemEntry::completeBaseName(), and d.
Referenced by Scanner::process().
QString QFileInfo::completeSuffix | ( | ) | const |
Returns the complete suffix (extension) of the file.
The complete suffix consists of all characters in the file after (but not including) the first '.'.
Example:
Definition at line 885 of file qfileinfo.cpp.
References d.
Referenced by QLibrary::isLibrary(), QV4::CompiledData::CompilationUnit::localCacheFilePath(), and QQuickNinePatchImage::pixmapChange().
QDir QFileInfo::dir | ( | ) | const |
Returns a QDir object representing the path of the parent directory of the file system entry that this QFileInfo refers to.
For each of the following, dir() returns the QDir {"~/examples/191697"}.
For each of the following, dir() returns the QDir {"."}.
Definition at line 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().
bool QFileInfo::exists | ( | ) | const |
Returns true
if the file system entry this QFileInfo refers to exists; otherwise returns false
.
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().
|
static |
Returns true
if the file system entry path exists; otherwise returns false
.
false
.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().
QString QFileInfo::fileName | ( | ) | const |
Returns the name of the file system entry this QFileInfo refers to, excluding the path. Example: \snippet code/src_corelib_io_qfileinfo.cpp 3
! [path-ends-with-slash-empty-name-component]
{'/'}, the entry's name part is considered empty. ! [path-ends-with-slash-empty-name-component] \sa isRelative(), filePath(), baseName(), suffix()
Definition at line 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().
QString QFileInfo::filePath | ( | ) | const |
Returns the path of the file system entry this QFileInfo refers to; the path may be absolute or relative.
Definition at line 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().
QDateTime QFileInfo::fileTime | ( | QFile::FileTime | time | ) | const |
QDateTime QFileInfo::fileTime | ( | QFile::FileTime | time, |
const QTimeZone & | tz ) const |
Returns the file time specified by \a time.
! [file-times-in-time-zone] The returned time is in the time zone specified by tz. For example, you can use QTimeZone::LocalTime or QTimeZone::UTC to get the time in the Local time zone or UTC, respectively. Since native file system API typically uses UTC, using QTimeZone::UTC is often faster, as it does not require any conversions. ! [file-times-in-time-zone]
If the time cannot be determined, an invalid date time is returned. \include qfileinfo.cpp info-about-target-not-symlink \since 6.6 \sa birthTime(const QTimeZone &), lastModified(const QTimeZone &), lastRead(const QTimeZone &), metadataChangeTime(const QTimeZone &), QDateTime::isValid()
Definition at line 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().
QString QFileInfo::group | ( | ) | const |
Returns the group of the file.
On Windows, on systems where files do not have groups, or if an error occurs, an empty string is returned.
This function can be time consuming under Unix (in the order of milliseconds).
info-about-target-not-symlink
Definition at line 1390 of file qfileinfo.cpp.
References d, and QAbstractFileEngine::OwnerGroup.
uint QFileInfo::groupId | ( | ) | const |
Returns the id of the group the file belongs to.
On Windows and on systems where files do not have groups this function always returns (uint) -2.
info-about-target-not-symlink
Definition at line 1408 of file qfileinfo.cpp.
References d, QFileSystemMetaData::GroupId, and QAbstractFileEngine::OwnerGroup.
Referenced by QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), and QWindowsFileSystemWatcherEngine::PathInfo::operator=().
|
inline |
Returns true
if the file system entry's path is absolute, otherwise returns false
(that is, the path is relative).
qresource-virtual-fs-colon
Definition at line 120 of file qfileinfo.h.
References isRelative().
Referenced by _qt_get_directory(), QTextDocument::loadResource(), and QTextBrowserPrivate::resolveUrl().
bool QFileInfo::isAlias | ( | ) | const |
Returns true
if this object points to an alias; otherwise returns false
.
Aliases only exist on \macos. They are treated as regular files, so opening an alias will open the file itself. In order to open the file or directory an alias references use symLinkTarget().
Definition at line 1220 of file qfileinfo.cpp.
References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.
bool QFileInfo::isBundle | ( | ) | const |
true
if this object points to a bundle or to a symbolic link to a bundle on \macos and iOS; otherwise returns false
.info-about-target-not-symlink
Definition at line 1107 of file qfileinfo.cpp.
References QAbstractFileEngine::BundleType, QFileSystemMetaData::BundleType, and d.
bool QFileInfo::isDir | ( | ) | const |
Returns true
if this object points to a directory or to a symbolic link to a directory.
Returns false
if the object points to something that is not a directory (such as a file) or that does not exist.
info-about-target-not-symlink
Definition at line 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().
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().
bool QFileInfo::isFile | ( | ) | const |
Returns true
if this object points to a file or to a symbolic link to a file.
Returns false
if the object points to something that is not a file (such as a directory) or that does not exist.
info-about-target-not-symlink
Definition at line 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().
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().
bool QFileInfo::isJunction | ( | ) | const |
Returns true
if the object points to a junction; otherwise returns false
.
Junctions only exist on Windows' NTFS file system, and are typically created by the {mklink} command. They can be thought of as symlinks for directories, and can only be created for absolute paths on the local volume.
Definition at line 1240 of file qfileinfo.cpp.
References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.
bool QFileInfo::isNativePath | ( | ) | const |
true
if the file path can be used directly with native APIs. Returns false
if the file is otherwise supported by a virtual file system inside Qt, such as \l{the Qt Resource System}.{Note:} Native paths may still require conversion of path separators and character encoding, depending on platform and input requirements of the native API.
Definition at line 1049 of file qfileinfo.cpp.
References d, and QAbstractFileEngine::LocalDiskFlag.
Referenced by QMimeDatabasePrivate::mimeTypeForFile().
bool QFileInfo::isReadable | ( | ) | const |
Returns true
if the user can read the file system entry this QFileInfo refers to; otherwise returns false
.
info-about-target-not-symlink
Definition at line 966 of file qfileinfo.cpp.
References d, QAbstractFileEngine::ReadUserPerm, and QFileSystemMetaData::UserReadPermission.
Referenced by QTextBrowserPrivate::findFile(), and QFileInfoGatherer::getInfo().
bool QFileInfo::isRelative | ( | ) | const |
Returns true
if the file system entry's path is relative, otherwise returns false
(that is, the path is absolute).
absolute-path-unix-windows
qresource-virtual-fs-colon
Definition at line 684 of file qfileinfo.cpp.
References d.
Referenced by QDir::isRelativePath(), QAndroidCaptureSession::start(), and QQmlJSImportVisitor::visit().
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().
bool QFileInfo::isShortcut | ( | ) | const |
Returns true
if this object points to a shortcut; otherwise returns false
.
Shortcuts only exist on Windows and are typically .lnk files. For instance, true will be returned for shortcuts (
*
.lnk files) on Windows, but false will be returned on Unix (including \macos and iOS).
The shortcut (.lnk) files are treated as regular files. Opening those will open the .lnk file itself. In order to open the file a shortcut references to, it must uses symLinkTarget() on a shortcut.
Definition at line 1196 of file qfileinfo.cpp.
References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.
bool QFileInfo::isSymbolicLink | ( | ) | const |
Returns true
if this object points to a symbolic link; otherwise returns false
.
Symbolic links exist on Unix (including \macos and iOS) and Windows (NTFS-symlink) and are typically created by the {ln -s} or
{mklink} commands, respectively.
Unix handles symlinks transparently. Opening a symbolic link effectively opens the \l{symLinkTarget()}{link's target}.
In contrast to isSymLink(), false will be returned for shortcuts (*
.lnk files) on Windows and aliases on \macos. Use QFileInfo::isShortcut() and QFileInfo::isAlias() instead.
symlink-target-exists-behavior
Definition at line 1170 of file qfileinfo.cpp.
References d, QFileSystemMetaData::LegacyLinkType, and QAbstractFileEngine::LinkType.
bool QFileInfo::isSymLink | ( | ) | const |
Returns \c true if this object points to a symbolic link, shortcut, or alias; otherwise returns \c false. Symbolic links exist on Unix (including \macos and iOS) and Windows and are typically created by the \c{ln -s} or \c{mklink} commands, respectively. Opening a symbolic link effectively opens the \l{symLinkTarget()}{link's target}. In addition, true will be returned for shortcuts (\c *.lnk files) on Windows, and aliases on \macos. This behavior is deprecated and will likely change in a future version of Qt. Opening a shortcut or alias will open the \c .lnk or alias file itself. Example: \snippet code/src_corelib_io_qfileinfo.cpp 9
! [symlink-target-exists-behavior]
true
if the symlink points to an existing target, otherwise it returns false
. ! [symlink-target-exists-behavior] \sa isFile(), isDir(), symLinkTarget()
Definition at line 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().
bool QFileInfo::isWritable | ( | ) | const |
Returns true
if the user can write to the file system entry this QFileInfo refers to; otherwise returns false
.
info-about-target-not-symlink
Definition at line 986 of file qfileinfo.cpp.
References d, QFileSystemMetaData::UserWritePermission, and QAbstractFileEngine::WriteUserPerm.
Referenced by ensureWritableDir(), ensureWritableDir(), and qt_ensureWritableDir().
QString QFileInfo::junctionTarget | ( | ) | const |
Resolves an NTFS junction to the path it references.
Returns the absolute path to the directory an NTFS junction points to, or an empty string if the object is not an NTFS junction.
There is no guarantee that the directory named by the NTFS junction actually exists.
Definition at line 1330 of file qfileinfo.cpp.
References d, and QAbstractFileEngine::JunctionName.
|
inline |
Returns the date and time when the file was last modified.
info-about-target-not-symlink
This function overloads \l{QFileInfo::lastModified(const QTimeZone &)}, and returns the same as {lastModified(QTimeZone::LocalTime)}.
Definition at line 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().
Returns the date and time when the file was last modified.
file-times-in-time-zone
info-about-target-not-symlink
Definition at line 166 of file qfileinfo.h.
References QFileDevice::FileModificationTime.
|
inline |
Returns the date and time when the file was last read (accessed).
On platforms where this information is not available, returns the same time as lastModified().
info-about-target-not-symlink
This function overloads \l{QFileInfo::lastRead(const QTimeZone &)}, and returns the same as {lastRead(QTimeZone::LocalTime)}.
Definition at line 161 of file qfileinfo.h.
References QFileDevice::FileAccessTime.
Returns the date and time when the file was last read (accessed).
file-times-in-time-zone
On platforms where this information is not available, returns the same time as lastModified().
info-about-target-not-symlink
Definition at line 167 of file qfileinfo.h.
References QFileDevice::FileAccessTime.
bool QFileInfo::makeAbsolute | ( | ) |
If the file system entry's path is relative, this method converts it to an absolute path and returns true
; if the path is already absolute, this method returns false
.
Definition at line 701 of file qfileinfo.cpp.
References absoluteFilePath(), QSharedDataPointer< T >::constData(), d_ptr, QFileInfoPrivate::fileEntry, QFileInfoPrivate::isDefaultConstructed, QFileSystemEntry::isRelative(), and setFile().
|
inline |
Returns the date and time when the file's metadata was last changed, in local time.
A metadata change occurs when the file is first created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions).
info-about-target-not-symlink
This function overloads QFileInfo::metadataChangeTime(const QTimeZone &tz), and returns the same as {metadataChangeTime(QTimeZone::LocalTime)}.
Definition at line 159 of file qfileinfo.h.
References QFileDevice::FileMetadataChangeTime.
Returns the date and time when the file's metadata was last changed.
A metadata change occurs when the file is first created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions).
file-times-in-time-zone
info-about-target-not-symlink
Definition at line 165 of file qfileinfo.h.
References QFileDevice::FileMetadataChangeTime.
Move-assigns other to this QFileInfo instance.
Makes a copy of the given fileinfo and assigns it to this QFileInfo.
\class QFileInfo \inmodule QtCore \reentrant \brief The QFileInfo class provides an OS-independent API to retrieve information about file system entries. \ingroup io \ingroup shared \compares equality QFileInfo provides information about a file system entry, such as its name, path, access rights and whether it is a regular file, directory or symbolic link. The entry's size and last modified/read times are also available. QFileInfo can also be used to obtain information about a Qt \l{resource system}{resource}. A QFileInfo can point to a file system entry with either an absolute or a relative path: \list \li \include qfileinfo.cpp absolute-path-unix-windows \li \include qfileinfo.cpp relative-path-note \endlist An example of an absolute path is the string \c {"/tmp/quartz"}. A relative path may look like \c {"src/fatlib"}. You can use the function isRelative() to check whether a QFileInfo is using a relative or an absolute path. You can call the function makeAbsolute() to convert a relative QFileInfo's path to an absolute path.
! [qresource-virtual-fs-colon]
The file system entry path that the QFileInfo works on is set in the constructor or later with setFile(). Use exists() to see if the entry actually exists and size() to get its size. The file system entry's type is obtained with isFile(), isDir(), and isSymLink(). The symLinkTarget() function provides the absolute path of the target the symlink points to. The path elements of the file system entry can be extracted with path() and fileName(). The fileName()'s parts can be extracted with baseName(), suffix(), or completeSuffix(). QFileInfo objects referring to directories created by Qt classes will not have a trailing directory separator \c{'/'}. If you wish to use trailing separators in your own file info objects, just append one to the entry's path given to the constructors or setFile(). Date and time related information are returned by birthTime(), fileTime(), lastModified(), lastRead(), and metadataChangeTime(). Information about access permissions can be obtained with isReadable(), isWritable(), and isExecutable(). Ownership information can be obtained with owner(), ownerId(), group(), and groupId(). You can also examine permissions and ownership in a single statement using the permission() function. \section1 Symbolic Links and Shortcuts On Unix (including \macos and iOS), the property getter functions in this class return the properties such as times and size of the target, not the symlink, because Unix handles symlinks transparently. Opening a symlink using QFile effectively opens the link's target. For example: \snippet code/src_corelib_io_qfileinfo.cpp 0 On Windows, shortcuts (\c .lnk files) are currently treated as symlinks. As on Unix systems, the property getters return the size of the target, not the \c .lnk file itself. This behavior is deprecated and will likely be removed in a future version of Qt, after which \c .lnk files will be treated as regular files. \snippet code/src_corelib_io_qfileinfo.cpp 1 \section1 NTFS permissions On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line: \snippet ntfsp.cpp 0 Permission checking is then turned on and off by incrementing and decrementing \c qt_ntfs_permission_lookup by 1. \snippet ntfsp.cpp 1 \note Since this is a non-atomic global variable, it is only safe to increment or decrement \c qt_ntfs_permission_lookup before any threads other than the main thread have started or after every thread other than the main thread has ended. \note From Qt 6.6 the variable \c qt_ntfs_permission_lookup is deprecated. Please use the following alternatives. The safe and easy way to manage permission checks is to use the RAII class \c QNtfsPermissionCheckGuard. \snippet ntfsp.cpp raii If you need more fine-grained control, it is possible to manage the permission with the following functions instead: \snippet ntfsp.cpp free-funcs \section1 Performance Considerations Some of QFileInfo's functions have to query the file system, but for performance reasons, some functions only operate on the path string. For example: To return the absolute path of a relative entry's path, absolutePath() has to query the file system. The path() function, however, can work on the file name directly, and so it is faster. QFileInfo also caches information about the file system entry it refers to. Because the file system can be changed by other users or programs, or even by other parts of the same program, there is a function that refreshes the information stored in QFileInfo, namely refresh(). To switch off a QFileInfo's caching (that is, force it to query the underlying file system every time you request information from it), call setCaching(false). Fetching information from the file system is typically done by calling (possibly) expensive system functions, so QFileInfo (depending on the implementation) might not fetch all the information from the file system at construction. To make sure that all information is read from the file system immediately, use the stat() member function. \l{birthTime()}, \l{fileTime()}, \l{lastModified()}, \l{lastRead()}, and \l{metadataChangeTime()} return times in \e{local time} by default. Since native file system API typically uses UTC, this requires a conversion. If you don't actually need the local time, you can avoid this by requesting the time in QTimeZone::UTC directly. \section1 Platform Specific Issues \include android-content-uri-limitations.qdocinc \sa QDir, QFile
Definition at line 480 of file qfileinfo.cpp.
References d_ptr.
QString QFileInfo::owner | ( | ) | const |
Returns the owner of the file.
On systems where files do not have owners, or if an error occurs, an empty string is returned.
This function can be time consuming under Unix (in the order of milliseconds). On Windows, it will return an empty string unless the \l{NTFS permissions} check has been enabled.
info-about-target-not-symlink
Definition at line 1351 of file qfileinfo.cpp.
References d, and QAbstractFileEngine::OwnerUser.
uint QFileInfo::ownerId | ( | ) | const |
Returns the id of the owner of the file.
On Windows and on systems where files do not have owners this function returns ((uint) -2).
info-about-target-not-symlink
Definition at line 1369 of file qfileinfo.cpp.
References d, QAbstractFileEngine::OwnerUser, and QFileSystemMetaData::UserId.
Referenced by QWindowsFileSystemWatcherEngine::PathInfo::operator!=(), and QWindowsFileSystemWatcherEngine::PathInfo::operator=().
QString QFileInfo::path | ( | ) | const |
Returns the path of the file system entry this QFileInfo refers to, excluding the entry's name.
path-ends-with-slash-empty-name-component In this case, this function will return the entire path.
Definition at line 655 of file qfileinfo.cpp.
References d.
Referenced by QCoreApplication::applicationDirPath(), deployPlugins(), RCCResourceLibrary::readFiles(), and QQuickImageSelector::setUrl().
bool QFileInfo::permission | ( | QFile::Permissions | permissions | ) | const |
Tests for file permissions.
The permissions argument can be several flags of type QFile::Permissions OR-ed together to check for permission combinations.
On systems where files do not have permissions this function always returns true
.
Example:
info-about-target-not-symlink
Definition at line 1435 of file qfileinfo.cpp.
References d, and permissions().
QFile::Permissions QFileInfo::permissions | ( | ) | const |
Returns the complete OR-ed together combination of QFile::Permissions for the file.
info-about-target-not-symlink
Definition at line 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().
QString QFileInfo::readSymLink | ( | ) | const |
Returns the raw path referenced by the symbolic link, without resolving a relative path relative to the directory containing the symbolic link. The returned string will only be an absolute path if the symbolic link actually references it as such. Returns an empty string if the object is not a symbolic link.
Definition at line 1308 of file qfileinfo.cpp.
References d, and QAbstractFileEngine::RawLinkPath.
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.
void QFileInfo::setCaching | ( | bool | enable | ) |
If enable is true, enables caching of file information.
If enable is false caching is disabled.
When caching is enabled, QFileInfo reads the file information from the file system the first time it's needed, but generally not later.
Caching is enabled by default.
Definition at line 1723 of file qfileinfo.cpp.
References d.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the path of the file system entry that this QFileInfo provides information about to path in directory dir.
preserve-relative-or-absolute
Definition at line 548 of file qfileinfo.cpp.
References dir(), QDir::filePath(), and setFile().
void QFileInfo::setFile | ( | const QFileDevice & | file | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the file that the QFileInfo provides information about to file.
If file includes a relative path, the QFileInfo will also have a relative path.
Definition at line 533 of file qfileinfo.cpp.
References file, QFile::fileName(), and setFile().
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().
qint64 QFileInfo::size | ( | ) | const |
Returns the file size in bytes.
If the file does not exist or cannot be fetched, 0 is returned.
info-about-target-not-symlink
Definition at line 1478 of file qfileinfo.cpp.
References QFileInfoPrivate::CachedSize, d, and QFileSystemMetaData::SizeAttribute.
Referenced by main(), QQmlDataBlob::SourceCodeData::readAll(), QDirEntryInfo::size(), and QExtendedInformation::size().
void QFileInfo::stat | ( | ) |
Reads all attributes from the file system.
This is useful when information about the file system is collected in a worker thread, and then passed to the UI in the form of caching QFileInfo instances.
Definition at line 1739 of file qfileinfo.cpp.
References QFileSystemMetaData::AllMetaDataFlags, d, and QFileSystemEngine::fillMetaData().
QString QFileInfo::suffix | ( | ) | const |
Returns the suffix (extension) of the file.
The suffix consists of all characters in the file after (but not including) the last '.'.
Example:
The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").
Definition at line 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().
Swaps this file info with other. This function is very fast and never fails.
Definition at line 60 of file qfileinfo.h.
References other().
QString QFileInfo::symLinkTarget | ( | ) | const |
Returns the absolute path to the file or directory a symbolic link points to, or an empty string if the object isn't a symbolic link.
This name may not represent an existing file; it is only a string.
symlink-target-exists-behavior
Definition at line 1289 of file qfileinfo.cpp.
References QAbstractFileEngine::AbsoluteLinkTarget, and d.
Referenced by QFileInfoGatherer::getInfo(), and QFile::symLinkTarget().
Definition at line 450 of file qfileinfo.cpp.
|
friend |
Definition at line 24 of file qfileinfo.h.
|
friend |
Definition at line 25 of file qfileinfo.h.
|
related |
Synonym for QList<QFileInfo>.
Definition at line 189 of file qfileinfo.h.
|
protected |
Definition at line 175 of file qfileinfo.h.
Referenced by makeAbsolute(), operator=(), and setFile().