.BI "bool \fBpermission\fR ( int permissionSpec ) const"
.br
.ti -1c
.BI "uint \fBsize\fR () const"
.br
.ti -1c
.BI "QDateTime \fBcreated\fR () const"
.br
.ti -1c
.BI "QDateTime \fBlastModified\fR () const"
.br
.ti -1c
.BI "QDateTime \fBlastRead\fR () const"
.br
.in -1c
.SH DESCRIPTION
The QFileInfo class provides system-independent file information.
.PP
QFileInfo provides information about a file's name and position (path) in the file system, its access rights and whether it is a directory or symbolic link, etc. The file's size and last modified/read times are also available.
.PP
A QFileInfo can point to a file with either a relative or an absolute file path. Absolute file paths begin with the directory separator "/" (or with a drive specification on Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current working directory. An example of an absolute path is the string "/tmp/quartz". A relative path might look like "src/fatlib". You can use the function isRelative() to check whether a QFileInfo is using a relative or an absolute file path. You can call the function convertToAbs() to convert a relative QFileInfo's path to an absolute path.
.PP
The file that the QFileInfo works on is set in the constructor or later with setFile(). Use exists() to see if the file exists and size() to get its size.
.PP
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).
.PP
The file's type is obtained with isFile(), isDir() and isSymLink(). The readLink() function provides the name of the file the symlink points to.
.PP
Elements of the file's name can be extracted with dirPath() and fileName(). The fileName()'s parts can be extracted with baseName() and extension().
.PP
The file's dates are returned by created(), lastModified() and lastRead(). Information about the file's access permissions is obtained with isReadable(), isWritable() and isExecutable(). The file's ownership is available from owner(), ownerId(), group() and groupId(). You can examine a file's permissions and ownership in a single statement using the permission() function.
.PP
If you need to read and traverse directories, see the QDir class.
.PP
See also Input/Output and Networking.
.SS "Member Type Documentation"
.SH "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.
.TP
\fCQFileInfo::ReadOwner\fR - The file is readable by the owner of the file.
.TP
\fCQFileInfo::WriteOwner\fR - The file is writable by the owner of the file.
.TP
\fCQFileInfo::ExeOwner\fR - The file is executable by the owner of the file.
.TP
\fCQFileInfo::ReadUser\fR - The file is readable by the user.
.TP
\fCQFileInfo::WriteUser\fR - The file is writable by the user.
.TP
\fCQFileInfo::ExeUser\fR - The file is executable by the user.
.TP
\fCQFileInfo::ReadGroup\fR - The file is readable by the group.
.TP
\fCQFileInfo::WriteGroup\fR - The file is writable by the group.
.TP
\fCQFileInfo::ExeGroup\fR - The file is executable by the group.
.TP
\fCQFileInfo::ReadOther\fR - The file is readable by anyone.
.TP
\fCQFileInfo::WriteOther\fR - The file is writable by anyone.
.TP
\fCQFileInfo::ExeOther\fR - The file is executable by anyone.
.PP
\fBWarning:\fR 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().
Constructs a new QFileInfo that gives information about the file called \fIfileName\fR in the directory \fId\fR.
.PP
If \fId\fR has a relative path, the QFileInfo will also have a relative path.
.PP
See also isRelative().
.SH "QFileInfo::QFileInfo ( const QFileInfo & fi )"
Constructs a new QFileInfo that is a copy of \fIfi\fR.
.SH "QFileInfo::~QFileInfo ()"
Destroys the QFileInfo and frees its resources.
.SH "QString QFileInfo::absFilePath () const"
Returns the absolute path including the file name.
.PP
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/'.
.PP
This function returns the same as filePath(), unless isRelative() is TRUE.
.PP
If the QFileInfo is empty it returns QDir::currentDirPath().
.PP
This function can be time consuming under Unix (in the order of milliseconds).
.PP
See also isRelative() and filePath().
.PP
Examples:
.)l biff/biff.cpp and fileiconview/qfileiconview.cpp.
If \fIcomplete\fR is FALSE (the default) the base name consists of all characters in the file name up to (but not including) the \fIfirst\fR '.' character.
.PP
If \fIcomplete\fR is TRUE the base name consists of all characters in the file up to (but not including) the \fIlast\fR '.' character.
.PP
The path is not included in either case.
.PP
Example:
.PP
.nf
.br
QFileInfo fi( "/tmp/archive.tar.gz" );
.br
QString base = fi.baseName(); // base = "archive"
.br
base = fi.baseName( TRUE ); // base = "archive.tar"
.br
.fi
.PP
See also fileName() and extension().
.SH "bool QFileInfo::caching () const"
Returns TRUE if caching is enabled; otherwise returns FALSE.
.PP
See also setCaching() and refresh().
.SH "bool QFileInfo::convertToAbs ()"
Converts the file's path to an absolute path.
.PP
If it is already absolute, nothing is done.
.PP
See also filePath() and isRelative().
.SH "QDateTime QFileInfo::created () const"
Returns the date and time when the file was created.
.PP
On platforms where this information is not available, returns the same as lastModified().
If \fIcomplete\fR is TRUE (the default), extension() returns the string of all characters in the file name after (but not including) the first '.' character.
.PP
If \fIcomplete\fR is FALSE, extension() returns the string of all characters in the file name after (but not including) the last '.' character.
.PP
Example:
.PP
.nf
.br
QFileInfo fi( "/tmp/archive.tar.gz" );
.br
QString ext = fi.extension(); // ext = "tar.gz"
.br
ext = fi.extension( FALSE ); // ext = "gz"
.br
.fi
.PP
See also fileName() and baseName().
.PP
Example: qdir/qdir.cpp.
.SH "QString QFileInfo::fileName () const"
Returns the name of the file, excluding the path.
.PP
Example:
.PP
.nf
.br
QFileInfo fi( "/tmp/archive.tar.gz" );
.br
QString name = fi.fileName(); // name = "archive.tar.gz"
.br
.fi
.PP
See also isRelative(), filePath(), baseName(), and extension().
.PP
Examples:
.)l dirview/dirview.cpp, fileiconview/qfileiconview.cpp, and network/ftpclient/ftpmainwindow.ui.h.
.SH "QString QFileInfo::filePath () const"
Returns the file name, including the path (which may be absolute or relative).
.PP
See also isRelative() and absFilePath().
.PP
Examples:
.)l dirview/main.cpp and fileiconview/qfileiconview.cpp.
.SH "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.
.PP
This function can be time consuming under Unix (in the order of milliseconds).
.PP
See also groupId(), owner(), and ownerId().
.SH "uint QFileInfo::groupId () const"
Returns the id of the group the file belongs to.
.PP
On Windows and on systems where files do not have groups this function always returns (uint) -2.
.PP
See also group(), owner(), and ownerId().
.SH "bool QFileInfo::isDir () const"
Returns TRUE if this object points to a directory or to a symbolic link to a directory; otherwise returns FALSE.
.PP
See also isFile() and isSymLink().
.PP
Examples:
.)l dirview/dirview.cpp and fileiconview/qfileiconview.cpp.
.SH "bool QFileInfo::isExecutable () const"
Returns TRUE if the file is executable; otherwise returns FALSE.
.PP
See also isReadable(), isWritable(), and permission().
.SH "bool QFileInfo::isFile () const"
Returns TRUE if this object points to a file. Returns FALSE if the object points to something which isn't a file, e.g. a directory or a symlink.
.PP
See also isDir() and isSymLink().
.PP
Examples:
.)l dirview/dirview.cpp, distributor/distributor.ui.h, fileiconview/qfileiconview.cpp, and qdir/qdir.cpp.
.SH "bool QFileInfo::isHidden () const"
Returns TRUE if the file is hidden; otherwise returns FALSE.
.PP
On Unix-like operating systems, including Mac OS X, a file is hidden if its name begins with ".". On Windows a file is hidden if its hidden attribute is set.
.SH "bool QFileInfo::isReadable () const"
Returns TRUE if the file is readable; otherwise returns FALSE.
.PP
See also isWritable(), isExecutable(), and permission().
.PP
Example: distributor/distributor.ui.h.
.SH "bool QFileInfo::isRelative () const"
Returns TRUE if the file path name is relative. Returns FALSE if the path is absolute (e.g. under Unix a path is absolute if it begins with a "/").
.SH "bool QFileInfo::isSymLink () const"
Returns TRUE if this object points to a symbolic link (or to a shortcut on Windows, or an alias on Mac OS X); otherwise returns FALSE.
.PP
See also isFile(), isDir(), and readLink().
.PP
Examples:
.)l dirview/dirview.cpp, distributor/distributor.ui.h, and fileiconview/qfileiconview.cpp.
.SH "bool QFileInfo::isWritable () const"
Returns TRUE if the file is writable; otherwise returns FALSE.
.PP
See also isReadable(), isExecutable(), and permission().
.PP
Example: distributor/distributor.ui.h.
.SH "QDateTime QFileInfo::lastModified () const"
Returns the date and time when the file was last modified.
.PP
See also created() and lastRead().
.PP
Example: biff/biff.cpp.
.SH "QDateTime QFileInfo::lastRead () const"
Returns the date and time when the file was last read (accessed).
.PP
On platforms where this information is not available, returns the same as lastModified().
.PP
See also created() and lastModified().
.PP
Example: biff/biff.cpp.
.SH "QFileInfo & QFileInfo::operator= ( const QFileInfo & fi )"
Makes a copy of \fIfi\fR and assigns it to this QFileInfo.
.SH "QString QFileInfo::owner () const"
Returns the owner of the file. On systems where files do not have owners, or if an error occurs, QString::null is returned.
.PP
This function can be time consuming under Unix (in the order of milliseconds).
.PP
See also ownerId(), group(), and groupId().
.SH "uint QFileInfo::ownerId () const"
Returns the id of the owner of the file.
.PP
On Windows and on systems where files do not have owners this function returns ((uint) -2).
.PP
See also owner(), group(), and groupId().
.SH "bool QFileInfo::permission ( int permissionSpec ) const"
Tests for file permissions. The \fIpermissionSpec\fR argument can be several flags of type PermissionSpec OR-ed together to check for permission combinations.
.PP
On systems where files do not have permissions this function always returns TRUE.
.PP
Example:
.PP
.nf
.br
QFileInfo fi( "/tmp/archive.tar.gz" );
.br
if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) )
Sets the file that the QFileInfo provides information about to \fIfile\fR.
.PP
The \fIfile\fR 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.
.PP
Example:
.PP
.nf
.br
QString absolute = "/local/bin";
.br
QString relative = "local/bin";
.br
QFileInfo absFile( absolute );
.br
QFileInfo relFile( relative );
.br
.br
QDir::setCurrent( QDir::rootDirPath() );
.br
// absFile and relFile now point to the same file
.br
.br
QDir::setCurrent( "/tmp" );
.br
// absFile now points to "/local/bin",
.br
// while relFile points to "/tmp/local/bin"
.br
.fi
.PP
See also isRelative(), QDir::setCurrent(), and QDir::isRelativePath().