QFileInfo(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

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 of ReadUser, WriteUser and ExeUser are 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 flags ReadOwner, WriteOwner and ExeOwner. If you want to find out the rights of the current user, you should use isReadable(), isWritable() and isExecutable(). 🚨

πŸ’– 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 β€” returns TRUE if this object points at a directory, or at a symbolic link that points at a directory πŸŽ€. Otherwise you get FALSE.

See also isFile() and isSymLink().

Examples: (yep, the docs have example links here β€” no snippet, just go peek πŸ‘€)

  • bool QFileInfo::isExecutable () const β€” TRUE if the file is executable, otherwise FALSE. Can I run it? That's the whole question. ✨

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

  • bool QFileInfo::isFile () const β€” TRUE if this object points at a file. And FALSE if 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 β€” TRUE if the file is hidden, otherwise FALSE. 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 β€” TRUE if the file is readable, otherwise FALSE. 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 β€” TRUE if the file path name is relative. FALSE if 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 β€” TRUE if this object points at a symbolic link (or a shortcut on Windows, or an alias on Mac OS X πŸ“); otherwise FALSE.

See also isFile(), isDir(), and readLink().

Examples: (linked in the docs, no snippet here)

  • bool QFileInfo::isWritable () const β€” TRUE if the file is writable, otherwise FALSE.

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 of fi and assigns it to this QFileInfo. 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::null comes 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 πŸ”₯. The permissionSpec argument can be several flags of type PermissionSpec OR-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 a QString::null if the object isn't a symbolic link.
Careful bestie: this name may not represent an existing file β€” it is only a string. QFileInfo::exists() returns TRUE if 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 ) β€” if enable is TRUE, enables caching of file information. If enable is FALSE, 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 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:

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, or 0 if the file does not exist, or if the size is 0, 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 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