Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QFileInfo Class Reference

List of all members.


Detailed Description

The QFileInfo class provides system-independent file information.

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. QFileInfo can also be used to obtain information about a Qt {resource system}{resource}.

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 makeAbsolute() to convert a relative QFileInfo's path to an absolute path.

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.

The file's type is obtained with isFile(), isDir() and isSymLink(). The symLinkTarget() function provides the name of the file the symlink points to.

On Unix (including Mac OS X), the symlink has the same size() has the file it points to, because Unix handles symlinks transparently; similarly, opening a symlink using QFile effectively opens the link's target. For example:

doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 0

On Windows, symlinks (shortcuts) are .lnk files. The reported size() is that of the symlink (not the link's target), and opening a symlink using QFile opens the .lnk file. For example:

doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 1

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

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.

Definition at line 60 of file qfileinfo.h.


Public Member Functions

QDir absoluteDir () const
QString absoluteFilePath () const
QString absolutePath () const
QString baseName () const
QString bundleName () const
bool caching () const
QString canonicalFilePath () const
QString canonicalPath () const
QString completeBaseName () const
QString completeSuffix () const
QDateTime created () const
void detach ()
QDir dir () const
bool exists () const
QString fileName () const
QString filePath () const
QString group () const
uint groupId () const
bool isAbsolute () const
bool isBundle () const
bool isDir () const
bool isExecutable () const
bool isFile () const
bool isHidden () const
bool isReadable () const
bool isRelative () const
bool isRoot () const
bool isSymLink () const
bool isWritable () const
QDateTime lastModified () const
QDateTime lastRead () const
bool makeAbsolute ()
bool operator!= (const QFileInfo &fileinfo) const
bool operator!= (const QFileInfo &fileinfo)
QFileInfooperator= (const QFileInfo &fileinfo)
bool operator== (const QFileInfo &fileinfo) const
bool operator== (const QFileInfo &fileinfo)
QString owner () const
uint ownerId () const
QString path () const
bool permission (QFile::Permissions permissions) const
QFile::Permissions permissions () const
 QFileInfo (const QFileInfo &fileinfo)
 QFileInfo (const QDir &dir, const QString &file)
 QFileInfo (const QFile &file)
 QFileInfo (const QString &file)
 QFileInfo ()
QString readLink () const
void refresh ()
void setCaching (bool on)
void setFile (const QDir &dir, const QString &file)
void setFile (const QFile &file)
void setFile (const QString &file)
qint64 size () const
QString suffix () const
QString symLinkTarget () const
 ~QFileInfo ()

Protected Attributes

QFileInfoPrivate * d_ptr

Related Functions

(Note that these are not member functions.)

 QFileInfoList

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index