QFileInfo 类

QFileInfo 类用于系统无关的文件信息。更多内容...

属性方法
头文件:#include <QFileInfo>
qmake:QT += core

注意 此类中所有函数均 可重入

公共成员函数

返回类型函数名
QFileInfo(const QFileInfo &fileinfo)
QFileInfo(const QDir &dir, const QString &file)
QFileInfo(const QFile &file)
QFileInfo(const QString &file)
QFileInfo()
QFileInfo &operator=(QFileInfo &&other)
QFileInfo &operator=(const QFileInfo &fileinfo)
~QFileInfo()
QDirabsoluteDir() const
QStringabsoluteFilePath() const
QStringabsolutePath() const
QStringbaseName() const
QDateTimebirthTime() const
QStringbundleName() const
boolcaching() const
QStringcanonicalFilePath() const
QStringcanonicalPath() const
QStringcompleteBaseName() const
QStringcompleteSuffix() const
QDirdir() const
boolexists() const
QStringfileName() const
QStringfilePath() const
QDateTimefileTime(QFile::FileTime time) const
QStringgroup() const
uintgroupId() const
boolisAbsolute() const
boolisBundle() const
boolisDir() const
boolisExecutable() const
boolisFile() const
boolisHidden() const
boolisJunction() const
boolisNativePath() const
boolisReadable() const
boolisRelative() const
boolisRoot() const
boolisShortcut() const
boolisSymLink() const
boolisSymbolicLink() const
boolisWritable() const
QDateTimelastModified() const
QDateTimelastRead() const
boolmakeAbsolute()
QDateTimemetadataChangeTime() const
QStringowner() const
uintownerId() const
QStringpath() const
boolpermission(QFile::Permissions permissions) const
QFile::Permissionspermissions() const
voidrefresh()
voidsetCaching(bool enable)
voidsetFile(const QString &file)
voidsetFile(const QFile &file)
voidsetFile(const QDir &dir, const QString &file)
qint64size() const
QStringsuffix() const
voidswap(QFileInfo &other)
QStringsymLinkTarget() const
booloperator!=(const QFileInfo &fileinfo) const
booloperator==(const QFileInfo &fileinfo) const

静态公共成员函数

返回类型函数名
boolexists(const QString &file)

相关非成员

返回类型函数名
typedefQFileInfoList

详细描述

QFileInfo 可以获取任一文件的名字、路径、访问权限、是否是文件夹及是否是符号链接等信息,也可以获取文件的大小、上次修改时间、上次读取时间,还可以获取 Qt 资源文件 的信息。

QFileInfo 可以表示相对路径也可以表示绝对路径。绝对路径以 “/” (windows 上以驱动符号)开头(例如 "/tmp/quartz"),相对路径以目录名或文件名开头,相对于当前工作目录(例如 "src/fatlib")。可以用 isRelative() 检查一个 QFileInfo 表示的是相对路径还是绝对路径。可以用 makeAbsolute() 将相对路径转为绝对路径。

QFileInfo 可以在构造函数中或稍后在 setFile() 设置文件,可以用 exists() 查看文件是否存在,可以用 size() 获取文件大小。

文件类型可以用 isFile()、isDir() 和 isSymLink() 获取。symLinkTarget() 函数提供了符号链接指向的文件名。

在 Unix 系统(包括 macOS 和 iOS),此类的属性的 getter 函数(例如获取时间或大小)返回的都是目标文件的值,而不是符号链接的(因为Unix透明地处理符号链接)。使用 QFile 打开符号链接实际上是打开链接的目标。举例如下:

#ifdef Q_OS_UNIX

QFileInfo info1("/home/bob/bin/untabify");
info1.isSymLink();          // returns true
info1.absoluteFilePath();   // returns "/home/bob/bin/untabify"
info1.size();               // returns 56201
info1.symLinkTarget();      // returns "/opt/pretty++/bin/untabify"

QFileInfo info2(info1.symLinkTarget());
info2.isSymLink();          // returns false
info2.absoluteFilePath();   // returns "/opt/pretty++/bin/untabify"
info2.size();               // returns 56201

#endif

在Windows上,快捷方式(“.lnk”文件)当前被视为符号链接。 和Unix系统一样,属性的 getter 返回目标文件的大小,而不是.lnk文件本身。 此行为已被弃用,并且可能会在Qt的未来版本中删除,此后,.lnk 文件将被视为常规文件。

#ifdef Q_OS_WIN

QFileInfo info1("C:\\Documents and Settings\\Bob\\untabify.lnk");
info1.isSymLink();          // returns true
info1.absoluteFilePath();   // returns "C:/Documents and Settings/Bob/untabify.lnk"
info1.size();               // returns 743
info1.symLinkTarget();      // returns "C:/Pretty++/untabify"

QFileInfo info2(info1.symLinkTarget());
info2.isSymLink();          // returns false
info2.absoluteFilePath();   // returns "C:/Pretty++/untabify"
info2.size();               // returns 63942

#endif

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

涉及文件日期的函数: birthTime() lastModified() lastRead() fileTime()

涉及文件访问权限的函数: isReadable() isWritable() isExecutable()

涉及文件所有权的函数: owner() ownerId() group() groupId()

同时查验文件权限及所有权: permission()

注意 在NTFS文件系统上,出于性能原因,默认情况下禁用所有权和权限检查。 要启用它,请包含以下行:

extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

然后,通过将qt_ntfs_permission_lookup递增和递减 1 来打开和关闭权限检查。

qt_ntfs_permission_lookup++; // 打开检查
qt_ntfs_permission_lookup--; // 再次关闭

性能问题

Some of QFileInfo's functions query the file system, but for performance reasons, some functions only operate on the file name itself. For example: To return the absolute path of a relative file name, absolutePath() has to query the file system. The path() function, however, can work on the file name directly, and so it is faster.

注意 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 is a function that refreshes the file information: refresh(). If you want to switch off a QFileInfo's caching and force it to access the file system every time you request information from it call setCaching(false).

另请参阅 QDir and QFile.

成员函数文档

QFileInfo::QFileInfo(const QFileInfo &fileinfo)

复制一个新的 QFileInfo。

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

构造一个新的 QFileInfo,表示指定 dir 目录中的 file 文件信息。

如果 dir 具有相对路径,则 QFileInfo 也将具有相对路径。

如果 file 是绝对路径,则 dir 指定的目录将被忽略。

另请参阅 isRelative()

QFileInfo::QFileInfo(const QFile &file)

构造一个新的 QFileInfo,表示指定的 file 文件信息。

如果文件具有相对路径,则 QFileInfo 也将具有相对路径。

另请参阅 isRelative()

QFileInfo::QFileInfo(const QString &file)

构造一个新的 QFileInfo,表示指定的 file 文件信息。file 可以包含绝对或相对路径。

另请参阅 setFile(),isRelative(),QDir::setCurrent() 和 QDir::isRelativePath()

QFileInfo::QFileInfo()

构造一个空的 QFileInfo 对象。

注意,空的 QFileInfo 对象不包含文件引用。

另请参阅 setFile()

QFileInfo &QFileInfo::operator=(QFileInfo &&other)

移动构造函数。

该函数在 Qt 5.2 引入

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

赋值构造函数。

QFileInfo::~QFileInfo()

析构函数。

QDir QFileInfo::absoluteDir() const

QDir 对象的形式返回文件的绝对路径。

另请参阅 dir(),filePath(),fileName() 和 isRelative()

QString QFileInfo::absoluteFilePath() const

返回包含文件名的绝对路径。

绝对路径名由完整路径和文件名组成。 在Unix上,它将始终以根目录“ /”开头。 在Windows上,它将始终以“ D:/”开头,其中D是驱动器号,但未映射到驱动器号的网络共享除外,在这种情况下,路径将以“ // sharename /”开头。 QFileInfo 将大写驱动器号。

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"

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.

警告 If filePath() is empty the behavior of this function is undefined.

另请参阅 filePath(), canonicalFilePath(), and isRelative().

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.

警告 If filePath() is empty the behavior of this function is undefined.

另请参阅 absoluteFilePath(), path(), canonicalPath(), fileName(), and isRelative().

QString QFileInfo::baseName() const

Returns the base name of the file without the path.

The base name consists of all characters in the file up to (but not including) the first '.' character.

Example:

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

The base name of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").

另请参阅 fileName(), suffix(), completeSuffix(), and completeBaseName()

QDateTime QFileInfo::birthTime() const

Returns the date and time when the file was created / born.

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 was introduced in Qt 5.10.

另请参阅 lastModified(), lastRead(), and metadataChangeTime()

QString QFileInfo::bundleName() const

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"

This function was introduced in Qt 4.3.

另请参阅 isBundle(), filePath(), baseName(), and suffix().

bool QFileInfo::caching() const

Returns true if caching is enabled; otherwise returns false.

另请参阅 setCaching() and refresh().

QString QFileInfo::canonicalFilePath() const

Returns the canonical path including the file name, i.e. an absolute path without symbolic links or redundant "." or ".." elements.

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

另请参阅 filePath(), absoluteFilePath(), and dir().

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.

另请参阅 path() and absolutePath().

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"

另请参阅 fileName(), suffix(), completeSuffix(), and baseName().

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"

另请参阅 fileName(), suffix(), baseName(), and completeBaseName().

QDir QFileInfo::dir() const

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

注意 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");

另请参阅 absolutePath(), filePath(), fileName(), isRelative(), and absoluteDir().

bool QFileInfo::exists() const

Returns true if the file exists; otherwise returns false.

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

[static]bool QFileInfo::exists(const QString &file)

Returns true if the file exists; otherwise returns false.

注意 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.

This function was introduced in Qt 5.2.

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"

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

另请参阅 isRelative(), filePath(), baseName(), and suffix().

QString QFileInfo::filePath() const

Returns the file name, including the path (which may be absolute or relative).

另请参阅 absoluteFilePath(), canonicalFilePath(), and isRelative().

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

Returns the file time specified by time. 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).

This function was introduced in Qt 5.10.

另请参阅 QFile::FileTime and QDateTime::isValid().

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

另请参阅 groupId(), owner(), and ownerId().

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

另请参阅 group(), owner(), and ownerId().

bool QFileInfo::isAbsolute() const

Returns true if the file path name is absolute, otherwise returns false if the path is relative.

另请参阅 isRelative().

bool QFileInfo::isBundle() const

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

This function was introduced in Qt 4.3.

另请参阅 isDir(), isSymLink(), and isFile().

bool QFileInfo::isDir() const

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

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

另请参阅 isFile(), isSymLink(), and isBundle().

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

另请参阅 isReadable(), isWritable(), and permission().

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 which isn't a file, such as a directory.

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

另请参阅 isDir(), isSymLink(), and isBundle().

bool QFileInfo::isHidden() const

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

注意 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).

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.

This function was introduced in Qt 5.15.

bool QFileInfo::isNativePath() const

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 the Qt Resource System.

注意 Native paths may still require conversion of path separators and character encoding, depending on platform and input requirements of the native API.

This function was introduced in Qt 5.0.

另请参阅 QDir::toNativeSeparators(), QFile::encodeName(), filePath(), absoluteFilePath(), and canonicalFilePath().

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

注意 If the NTFS permissions check has not been enabled, the result on Windows will merely reflect whether the file exists.

另请参阅 isWritable(), isExecutable(), and permission().

bool QFileInfo::isRelative() const

Returns true if the file path name is relative, otherwise returns false if the path is absolute (e.g. under Unix a path is absolute if it begins with a "/").

另请参阅 isAbsolute().

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.

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.

注意 Even if a shortcut (broken shortcut) points to a non existing file, isShortcut() returns true.

另请参阅 isFile(), isDir(), isSymbolicLink(), and symLinkTarget().

bool QFileInfo::isSymLink() const

Returns true if this object points to a symbolic link or shortcut; 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 link's target.

In addition, true will be returned for shortcuts (*.lnk files) on Windows. This behavior is deprecated and will likely change in a future version of Qt. Opening those will open the .lnk file itself.

Example:

QFileInfo info(fileName);
if (info.isSymLink())
    fileName = info.symLinkTarget();

注意 If the symlink points to a non existing file, exists() returns false.

另请参阅 isFile(), isDir(), and symLinkTarget().

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 link's target.

In contrast to isSymLink(), false will be returned for shortcuts (*.lnk files) on Windows. Use QFileInfo::isShortcut() instead.

注意 If the symlink points to a non existing file, exists() returns false.

另请参阅 isFile(), isDir(), isShortcut(), and symLinkTarget().

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

注意 If the NTFS permissions check has not been enabled, the result on Windows will merely reflect whether the file is marked as Read Only.

另请参阅 isReadable(), isExecutable(), and permission().

QDateTime QFileInfo::lastModified() const

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

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

另请参阅 birthTime(), lastRead(), metadataChangeTime(), and fileTime().

QDateTime QFileInfo::lastRead() const

Returns the date and local time when the file was last read (accessed).

On platforms where this information is not available, returns the same as lastModified().

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

另请参阅 birthTime(), lastModified(), metadataChangeTime(), and fileTime().

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.

另请参阅 filePath() and isRelative().

QDateTime QFileInfo::metadataChangeTime() const

Returns the date and time when the file metadata was changed. A metadata change occurs when the file is 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 was introduced in Qt 5.10.

另请参阅 lastModified() and lastRead().

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 NTFS permissions check has been enabled.

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

另请参阅 ownerId(), group(), and groupId().

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

另请参阅 owner(), group(), and groupId().

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.

另请参阅 filePath(), absolutePath(), canonicalPath(), dir(), fileName(), and isRelative().

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.

注意 The result might be inaccurate on Windows if the NTFS permissions check has not been enabled.

Example:

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

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

另请参阅 isReadable(), isWritable(), and isExecutable().

QFile::Permissions QFileInfo::permissions() const

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

注意 The result might be inaccurate on Windows if the NTFS permissions check has not been enabled.

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

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.

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.

另请参阅 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::rootPath());
// 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"

另请参阅 isFile(), isRelative(), QDir::setCurrent(), and QDir::isRelativePath().

void QFileInfo::setFile(const QFile &file)

This is an overloaded 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.

另请参阅 isRelative().

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

This is an overloaded function.

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.

另请参阅 isRelative().

qint64 QFileInfo::size() const

Returns the file size in bytes. If the file does not exist or cannot be fetched, 0 is returned.

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

另请参阅 exists().

QString QFileInfo::suffix() const

Returns the suffix (extension) of the file.

The suffix consists of all characters in the file after (but not including) the last '.'.

Example:

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

The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").

另请参阅 fileName(), completeSuffix(), baseName(), and completeBaseName().

void QFileInfo::swap(QFileInfo &other)

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

This function was introduced in Qt 5.0.

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. QFileInfo::exists() returns true if the symlink points to an existing file.

This function was introduced in Qt 4.2.

另请参阅 exists(), isSymLink(), isDir(), and isFile().

bool QFileInfo::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.

另请参阅 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.

警告 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.

另请参阅 operator!=()

QFileInfoList

等同于 QList<QFileInfo>