QFileInfo(3qt)
okay bestie, pull up a chair π you're looking at QFileInfo from the Qt manual β that's the 3qt page, iykyk. she's the class that gives you system-independent file information: where a file lives, what it's called, who's allowed to touch it, whether it's a dir or a symlink, how big it is, and when it was last read or written. main character energy, no cap.
β¨ NAME β¨
QFileInfo β System-independent file information π
π¦ SYNOPSIS π¦
All the functions in this class are reentrant when Qt is built with thread support.</p>
(fr fr, that stray </p> is literally just sitting there in the original, not my typo π)
#include <qfileinfo.h>
π Public Members
enum PermissionSpec { ReadOwner = 04000, WriteOwner = 02000, ExeOwner =
01000, ReadUser = 00400, WriteUser = 00200, ExeUser = 00100,
ReadGroup = 00040, WriteGroup = 00020, ExeGroup = 00010, ReadOther =
00004, WriteOther = 00002, ExeOther = 00001 }
QFileInfo ()
QFileInfo ( const QString & file )
QFileInfo ( const QFile & file )
QFileInfo ( const QDir & d, const QString & fileName )
QFileInfo ( const QFileInfo & fi )
~QFileInfo ()
QFileInfo & operator= ( const QFileInfo & fi )
void setFile ( const QString & file )
void setFile ( const QFile & file )
void setFile ( const QDir & d, const QString & fileName )
bool exists () const
void refresh () const
bool caching () const
void setCaching ( bool enable )
QString filePath () const
QString fileName () const
QString absFilePath () const
QString baseName ( bool complete = FALSE ) const
QString extension ( bool complete = TRUE ) const
QString dirPath ( bool absPath = FALSE ) const
QDir dir ( bool absPath = FALSE ) const
bool isReadable () const
bool isWritable () const
bool isExecutable () const
bool isHidden () const
bool isRelative () const
bool convertToAbs ()
bool isFile () const
bool isDir () const
bool isSymLink () const
QString readLink () const
QString owner () const
uint ownerId () const
QString group () const
uint groupId () const
bool permission ( int permissionSpec ) const
uint size () const
QDateTime created () const
QDateTime lastModified () const
QDateTime lastRead () const
πΈ DESCRIPTION πΈ
The QFileInfo class provides system-independent file information. π
So like, QFileInfo gives you the tea on a file's name and position (that's its path) in the file system, plus its access rights, plus whether it's a directory or a symbolic link, etc. The file's size and its last modified/read times are also right there for you. obsessed.
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. Example of an absolute path: the string "/tmp/quartz". A relative path might look like "src/fatlib". Use isRelative() to check whether a QFileInfo is running on a relative or absolute file path, and call convertToAbs() to convert a relative QFileInfo's path into an absolute one. periodt.
The file that the QFileInfo works on is set in the constructor, or later with setFile(). Use exists() to see if the file actually exists and size() to get its size. β¨
To speed up performance, QFileInfo caches information about the file. Because files can be changed by other users or programs, or even by other parts of the same program π, there's a function that refreshes the file information: refresh(). And if you want to switch off a QFileInfo's caching entirely and force it to hit the file system every single time you request info from it, call setCaching(FALSE).
The file's type comes from isFile(), isDir() and isSymLink(). The readLink() function hands you the name of the file the symlink points to. π
Elements of the file's name can be extracted with dirPath() and fileName(). And the fileName()'s parts can be extracted with baseName() and extension().
The file's dates are returned by created(), lastModified() and lastRead(). Info about the file's access permissions comes from isReadable(), isWritable() and isExecutable(). The file's ownership is available from owner(), ownerId(), group() and groupId(). And you can examine a file's permissions and ownership in a single statement using the permission() function. iconic.
If you need to read and traverse directories, see the QDir class. π
See also Input/Output and Networking.
π§ Member Type Documentation
QFileInfo::PermissionSpec
This enum is used by the permission() function to report the permissions and ownership of a file. The values may be OR-ed together to test multiple permissions and ownership values.
QFileInfo::ReadOwnerβ The file is readable by the owner of the file.QFileInfo::WriteOwnerβ The file is writable by the owner of the file.QFileInfo::ExeOwnerβ The file is executable by the owner of the file.QFileInfo::ReadUserβ The file is readable by the user.QFileInfo::WriteUserβ The file is writable by the user.QFileInfo::ExeUserβ The file is executable by the user.QFileInfo::ReadGroupβ The file is readable by the group.QFileInfo::WriteGroupβ The file is writable by the group.QFileInfo::ExeGroupβ The file is executable by the group.QFileInfo::ReadOtherβ The file is readable by anyone.QFileInfo::WriteOtherβ The file is writable by anyone.QFileInfo::ExeOtherβ The file is executable by anyone.
Warning: The semantics ofReadUser,WriteUserandExeUserare unfortunately not platform independent: on Unix, the rights of the owner of the file are returned, and on Windows the rights of the current user are returned. This behavior might change in a future Qt version. If you want to find the rights of the owner of the file, you should use the flagsReadOwner,WriteOwnerandExeOwner. If you want to find out the rights of the current user, you should useisReadable(),isWritable()andisExecutable(). π¨
π MEMBER FUNCTION DOCUMENTATION π
QFileInfo::QFileInfo ()
Constructs a new empty QFileInfo. π«Ά
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.
Warning: Some functions might behave in a counter-intuitive way if file has a trailing directory separator. π
See also setFile(), isRelative(), QDir::setCurrent(), and QDir::isRelativePath().
QFileInfo::QFileInfo ( const QFile & 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().
QFileInfo::QFileInfo ( const QDir & d, const QString & fileName )
Constructs a new QFileInfo that gives information about the file called fileName in the directory d.
If d has a relative path, the QFileInfo will also have a relative path.
See also isRelative().
QFileInfo::QFileInfo ( const QFileInfo & fi )
Constructs a new QFileInfo that is a copy of fi. π
QFileInfo::~QFileInfo ()
Destroys the QFileInfo and frees its resources. bye bestie π
QString QFileInfo::absFilePath () const
Returns the 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/'.
This function returns the same as filePath(), unless isRelative() is TRUE.
If the QFileInfo is empty it returns QDir::currentDirPath().
This function can be time consuming under Unix (in the order of milliseconds). β³
See also isRelative() and filePath().
Examples:
QString QFileInfo::baseName ( bool complete = FALSE ) const
Returns the base name of the file.
If complete is FALSE (the default) the base name consists of all characters in the file name up to (but not including) the first '.' character.
If complete is TRUE the base name consists of all characters in the file up to (but not including) the last '.' character.
The path is not included in either case.
Example:
QFileInfo fi( "/tmp/archive.tar.gz" );
QString base = fi.baseName(); // base = "archive"
base = fi.baseName( TRUE ); // base = "archive.tar"
See also fileName() and extension().
bool QFileInfo::caching () const
Returns TRUE if caching is enabled; otherwise returns FALSE.
See also setCaching() and refresh().
bool QFileInfo::convertToAbs ()
Converts the file's path to an absolute path.
If it is already absolute, nothing is done. β¨
See also filePath() and isRelative().
QDateTime QFileInfo::created () const
Returns the date and time when the file was created.
On platforms where this information is not available, returns the same as lastModified().
See also lastModified() and lastRead().
QDir QFileInfo::dir ( bool absPath = FALSE ) const
Returns the file's path as a QDir object.
If the QFileInfo is relative and absPath is FALSE, the QDir will be relative; otherwise it will be absolute.
See also dirPath(), filePath(), fileName(), and isRelative().
Example: fileiconview/qfileiconview.cpp.
QString QFileInfo::dirPath ( bool absPath = FALSE ) const
Returns the file's path.
If absPath is TRUE an absolute path is returned.
See also dir(), filePath(), fileName(), and isRelative().
Example: fileiconview/qfileiconview.cpp.
bool QFileInfo::exists () const
Returns TRUE if the file exists; otherwise returns FALSE.
Examples:
QString QFileInfo::extension ( bool complete = TRUE ) const
Returns the file's extension name.
If complete is TRUE (the default), extension() returns the string of all characters in the file name after (but not including) the first '.' character.
If complete is FALSE, extension() returns the string of all characters in the file name after (but not including) the last '.' character.
Example:
QFileInfo fi( "/tmp/archive.tar.gz" );
QString ext = fi.extension(); // ext = "tar.gz"
ext = fi.extension( FALSE ); // ext = "gz"
See also fileName() and baseName().
Example: qdir/qdir.cpp.
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"
See also isRelative(), filePath(), baseName(), and extension().
Examples:
QString QFileInfo::filePath () const
Returns the file name, including the path (which may be absolute or relative).
See also isRelative() and absFilePath().
Examples:
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, QString::null is returned.
This function can be time consuming under Unix (in the order of milliseconds). β³
See also groupId(), owner(), and ownerId().
uint QFileInfo::groupId () constβ hands you the id of the group this file belongs to. π But heads up bestie: on Windows, and on any system where files literally do not have groups, this thing always returns(uint) -2. No group, no vibe.
See also group(), owner(), and ownerId().
bool QFileInfo::isDir () constβ returnsTRUEif this object points at a directory, or at a symbolic link that points at a directory π. Otherwise you getFALSE.
See also isFile() and isSymLink().
Examples: (yep, the docs have example links here β no snippet, just go peek π)
bool QFileInfo::isExecutable () constβTRUEif the file is executable, otherwiseFALSE. Can I run it? That's the whole question. β¨
See also isReadable(), isWritable(), and permission().
bool QFileInfo::isFile () constβTRUEif this object points at a file. AndFALSEif it points at something that isn't a file β like a directory, or a symlink. π¦ It's giving "not a regular file, sorry babe".
See also isDir() and isSymLink().
Examples: (linked in the docs, no code shown here)
bool QFileInfo::isHidden () constβTRUEif the file is hidden, otherwiseFALSE. On Unix-like systems (Mac OS X included π ) a file counts as hidden if its name begins with".". On Windows it's hidden if its hidden attribute is set. Different platforms, different rules, same drama.bool QFileInfo::isReadable () constβTRUEif the file is readable, otherwiseFALSE. Can I read it? That's it, that's the function. πΈ
See also isWritable(), isExecutable(), and permission().
Example: distributor/distributor.ui.h.
bool QFileInfo::isRelative () constβTRUEif the file path name is relative.FALSEif the path is absolute (so under Unix, a path is absolute if it begins with a"/"). π§ Absolute vs relative, the eternal plotline.bool QFileInfo::isSymLink () constβTRUEif this object points at a symbolic link (or a shortcut on Windows, or an alias on Mac OS X π); otherwiseFALSE.
See also isFile(), isDir(), and readLink().
Examples: (linked in the docs, no snippet here)
bool QFileInfo::isWritable () constβTRUEif the file is writable, otherwiseFALSE.
See also isReadable(), isExecutable(), and permission().
Example: distributor/distributor.ui.h.
QDateTime QFileInfo::lastModified () constβ the date and time when the file was last modified. β° The "when did you last change, bestie" function.
See also created() and lastRead().
Example: biff/biff.cpp.
QDateTime QFileInfo::lastRead () constβ the date and time when the file was last read (accessed) π.
On platforms where this information isn't available, it returns the same thing as lastModified(). No data? You get the modified time instead. Lowkey a substitute.
See also created() and lastModified().
Example: biff/biff.cpp.
QFileInfo & QFileInfo::operator= ( const QFileInfo & fi )β makes a copy offiand assigns it to thisQFileInfo. Copy-paste, but make it operator. π«ΆQString QFileInfo::owner () constβ returns the owner of the file. On systems where files don't have owners, or if an error happens,QString::nullcomes back. π
Heads up: this function can be time consuming under Unix β we're talking in the order of milliseconds. So don't be calling it in a hot loop, fr fr.
See also ownerId(), group(), and groupId().
uint QFileInfo::ownerId () constβ returns the id of the owner of the file.
On Windows, and on systems where files don't have owners, this function returns ((uint) -2). Not a real id, just the "nope" value. π
See also owner(), group(), and groupId().
bool QFileInfo::permission ( int permissionSpec ) constβ tests for file permissions π₯. ThepermissionSpecargument can be several flags of typePermissionSpecOR-ed together, so you can check whole permission combinations at once.
On systems where files don't have permissions, this function always returns TRUE. (Everyone's got permission when nobody's got permissions, iconic.)
Example:
QFileInfo fi( "/tmp/archive.tar.gz" );
if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) )
qWarning( "I can change the file; my group can read the file" );
if ( fi.permission( QFileInfo::WriteGroup | QFileInfo::WriteOther ) )
qWarning( "The group or others can change the file" );
See also isReadable(), isWritable(), and isExecutable().
QString QFileInfo::readLink () constβ returns the name that a symlink (or a shortcut on Windows) points to, or aQString::nullif the object isn't a symbolic link.
Careful bestie: this name may not represent an existing file β it is only a string.QFileInfo::exists()returnsTRUEif the symlink actually points to an existing file. String β real file, ok? π
See also exists(), isSymLink(), isDir(), and isFile().
void QFileInfo::refresh () constβ refreshes the information about the file, i.e. it reads in information from the file system the next time a cached property is fetched. Like hitting reload on the vibes. π
See also setCaching().
void QFileInfo::setCaching ( bool enable )β ifenableisTRUE, enables caching of file information. IfenableisFALSE, caching is disabled.
When caching is on, QFileInfo reads the file information from the file system the first time it's needed, but generally not later. So it remembers, and remembering is the whole point. β¨
Caching is enabled by default.
See also refresh() and caching().
void QFileInfo::setFile ( const QString & file )β sets the file that theQFileInfoprovides information about tofile.
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:
QString absolute = "/local/bin";
QString relative = "local/bin";
QFileInfo absFile( absolute );
QFileInfo relFile( relative );
QDir::setCurrent( QDir::rootDirPath() );
// absFile and relFile now point to the same file
QDir::setCurrent( "/tmp" );
// absFile now points to "/local/bin",
// while relFile points to "/tmp/local/bin"
See also isRelative(), QDir::setCurrent(), and QDir::isRelativePath().
Example: biff/biff.cpp.
void QFileInfo::setFile ( const QFile & file )β this is an overloaded member function, provided for convenience π. It behaves essentially like the above function.
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().
void QFileInfo::setFile ( const QDir & d, const QString & fileName )β another overloaded member function, again provided for convenience. Behaves essentially like the above function.
Sets the file that the QFileInfo provides information about to fileName in directory d.
If fileName includes a relative path, the QFileInfo will also have a relative path.
See also isRelative().
uint QFileInfo::size () constβ returns the file size in bytes, or0if the file does not exist, or if the size is0, or if the size cannot be fetched. Three different ways to get a zero, one single return value. π
Example: qdir/qdir.cpp.
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
β¨ AUTHOR β¨
Generated automatically from the source code. (Yes, a robot wrote it. A very 2007 robot. π€π )
π BUGS π
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. π«Ά
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. π (man page girlies, we're on our own)
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qfileinfo.3qt) and the Qt version (3.3.8). π
And that's a wrap on part 2, bestie!! πβ¨ This whole thing came from Trolltech AS, dated 2 February 2007, filed under QFileInfo(3qt) β go forth and stat responsibly, mwah ππ¦
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms