Eneboo - Documentación para desarrolladores
Tipos públicos | Métodos públicos | Amigas
Referencia de la Clase QFileInfo

The QFileInfo class provides system-independent file information. Más...

#include <qfileinfo.h>

Lista de todos los miembros.

Tipos públicos

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,
  ReadOwner = 04000, WriteOwner = 02000, ExeOwner = 01000, ReadUser = 00400,
  WriteUser = 00200, ExeUser = 00100, ReadGroup = 00040, WriteGroup = 00020,
  ExeGroup = 00010, ReadOther = 00004, WriteOther = 00002, ExeOther = 00001
}
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,
  ReadOwner = 04000, WriteOwner = 02000, ExeOwner = 01000, ReadUser = 00400,
  WriteUser = 00200, ExeUser = 00100, ReadGroup = 00040, WriteGroup = 00020,
  ExeGroup = 00010, ReadOther = 00004, WriteOther = 00002, ExeOther = 00001
}

Métodos públicos

 QFileInfo ()
 QFileInfo (const QString &file)
 QFileInfo (const QFile &)
 QFileInfo (const QDir &, const QString &fileName)
 QFileInfo (const QFileInfo &)
 ~QFileInfo ()
QFileInfooperator= (const QFileInfo &)
void setFile (const QString &file)
void setFile (const QFile &)
void setFile (const QDir &, const QString &fileName)
bool exists () const
void refresh () const
bool caching () const
void setCaching (bool)
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
 QFileInfo ()
 QFileInfo (const QString &file)
 QFileInfo (const QFile &)
 QFileInfo (const QDir &, const QString &fileName)
 QFileInfo (const QFileInfo &)
 ~QFileInfo ()
QFileInfooperator= (const QFileInfo &)
void setFile (const QString &file)
void setFile (const QFile &)
void setFile (const QDir &, const QString &fileName)
bool exists () const
void refresh () const
bool caching () const
void setCaching (bool)
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

Amigas

class QDeepCopy< QFileInfo >

Descripción detallada

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.

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.

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.

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

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

Elements of the file's name can be extracted with dirPath() and fileName(). The fileName()'s parts can be extracted with baseName() and extension().

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.

If you need to read and traverse directories, see the QDir class.


Documentación de las enumeraciones miembro de la clase

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.

ReadOwner The file is readable by the owner of the file. WriteOwner The file is writable by the owner of the file. ExeOwner The file is executable by the owner of the file. ReadUser The file is readable by the user. WriteUser The file is writable by the user. ExeUser The file is executable by the user. ReadGroup The file is readable by the group. WriteGroup The file is writable by the group. ExeGroup The file is executable by the group. ReadOther The file is readable by anyone. WriteOther The file is writable by anyone. ExeOther The file is executable by anyone.

Atención:
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().
Valores de enumeraciones:
ReadOwner 
WriteOwner 
ExeOwner 
ReadUser 
WriteUser 
ExeUser 
ReadGroup 
WriteGroup 
ExeGroup 
ReadOther 
WriteOther 
ExeOther 
ReadOwner 
WriteOwner 
ExeOwner 
ReadUser 
WriteUser 
ExeUser 
ReadGroup 
WriteGroup 
ExeGroup 
ReadOther 
WriteOther 
ExeOther 
Valores de enumeraciones:
ReadOwner 
WriteOwner 
ExeOwner 
ReadUser 
WriteUser 
ExeUser 
ReadGroup 
WriteGroup 
ExeGroup 
ReadOther 
WriteOther 
ExeOther 
ReadOwner 
WriteOwner 
ExeOwner 
ReadUser 
WriteUser 
ExeUser 
ReadGroup 
WriteGroup 
ExeGroup 
ReadOther 
WriteOther 
ExeOther 

Documentación del constructor y destructor

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.

Atención:
Some functions might behave in a counter-intuitive way if file has a trailing directory separator.
Ver también:
setFile(), isRelative(), QDir::setCurrent(), 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.

Ver también:
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.

Ver también:
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.

QFileInfo::QFileInfo ( )
QFileInfo::QFileInfo ( const QString file)
QFileInfo::QFileInfo ( const QFile )
QFileInfo::QFileInfo ( const QDir ,
const QString fileName 
)
QFileInfo::QFileInfo ( const QFileInfo )
QFileInfo::~QFileInfo ( )

Documentación de las funciones miembro

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

Ver también:
isRelative(), filePath()
QString QFileInfo::absFilePath ( ) const
QString QFileInfo::baseName ( bool  complete = FALSE) const
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"
Ver también:
fileName(), extension()
bool QFileInfo::caching ( ) const [inline]

Returns TRUE if caching is enabled; otherwise returns FALSE.

Ver también:
setCaching(), refresh()
bool QFileInfo::caching ( ) const
bool QFileInfo::convertToAbs ( )

Converts the file's path to an absolute path.

If it is already absolute, nothing is done.

Ver también:
filePath(), isRelative()
bool QFileInfo::convertToAbs ( )
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().

Ver también:
created() lastModified() lastRead()
QDateTime QFileInfo::created ( ) const
QDir QFileInfo::dir ( bool  absPath = FALSE) const
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.

Ver también:
dirPath(), filePath(), fileName(), isRelative()
QString QFileInfo::dirPath ( bool  absPath = FALSE) const
QString QFileInfo::dirPath ( bool  absPath = FALSE) const

Returns the file's path.

If absPath is TRUE an absolute path is returned.

Ver también:
dir(), filePath(), fileName(), isRelative()

Returns the directory path of the file.

If absPath is TRUE an absolute path is returned.

Ver también:
dir(), filePath(), fileName(), isRelative()
bool QFileInfo::exists ( ) const
bool QFileInfo::exists ( ) const

Returns TRUE if the file exists; otherwise returns FALSE.

QString QFileInfo::extension ( bool  complete = TRUE) const
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"
Ver también:
fileName(), baseName()
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"
Ver también:
isRelative(), filePath(), baseName(), extension()

Returns the name of the file, the file path is not included.

Example:

     QFileInfo fi( "/tmp/archive.tar.gz" );
     QString name = fi.fileName();                // name = "archive.tar.gz"
Ver también:
isRelative(), filePath(), baseName(), extension()
QString QFileInfo::fileName ( ) const
QString QFileInfo::filePath ( ) const
QString QFileInfo::filePath ( ) const

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

Ver también:
isRelative(), absFilePath()
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).

Ver también:
groupId(), owner(), ownerId()

Returns the group of the file. On Windows, on systems where files do not have groups, or if an error occurs, a null string is returned.

This function can be time consuming under Unix (in the order of milliseconds).

Ver también:
groupId(), owner(), ownerId()
QString QFileInfo::group ( ) const
uint QFileInfo::groupId ( ) const
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.

Ver también:
group(), owner(), ownerId()
bool QFileInfo::isDir ( ) const

Returns TRUE if this object points to a directory or to a symbolic link to a directory; otherwise returns FALSE.

Ver también:
isFile(), isSymLink()
bool QFileInfo::isDir ( ) const
bool QFileInfo::isExecutable ( ) const

Returns TRUE if the file is executable; otherwise returns FALSE.

Ver también:
isReadable(), isWritable(), permission()
bool QFileInfo::isExecutable ( ) const
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.

Ver también:
isDir(), isSymLink()
bool QFileInfo::isFile ( ) const
bool QFileInfo::isHidden ( ) const

Returns TRUE if the file is hidden; otherwise returns FALSE.

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.

bool QFileInfo::isHidden ( ) const
bool QFileInfo::isReadable ( ) const

Returns TRUE if the file is readable; otherwise returns FALSE.

Ver también:
isWritable(), isExecutable(), permission()
bool QFileInfo::isReadable ( ) const
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 "/").

bool QFileInfo::isRelative ( ) const
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.

Ver también:
isFile(), isDir(), readLink()

Returns TRUE if this object points to a symbolic link (or to a shortcut on Windows); otherwise returns FALSE.

Ver también:
isFile(), isDir(), readLink()
bool QFileInfo::isSymLink ( ) const
bool QFileInfo::isWritable ( ) const

Returns TRUE if the file is writable; otherwise returns FALSE.

Ver también:
isReadable(), isExecutable(), permission()
bool QFileInfo::isWritable ( ) const
QDateTime QFileInfo::lastModified ( ) const

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

Ver también:
created() lastModified() lastRead()
QDateTime QFileInfo::lastModified ( ) const
QDateTime QFileInfo::lastRead ( ) const

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

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

Ver también:
created() lastModified() lastRead()
QDateTime QFileInfo::lastRead ( ) const
QFileInfo& QFileInfo::operator= ( const QFileInfo )
QFileInfo & QFileInfo::operator= ( const QFileInfo fi)

Makes a copy of fi and assigns it to this QFileInfo.

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.

This function can be time consuming under Unix (in the order of milliseconds).

Ver también:
ownerId(), group(), groupId()

Returns the owner of the file. On Windows, on systems where files do not have owners, or if an error occurs, a null string is returned.

This function can be time consuming under Unix (in the order of milliseconds).

Ver también:
ownerId(), group(), groupId()
QString QFileInfo::owner ( ) const
uint QFileInfo::ownerId ( ) const
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).

Ver también:
owner(), group(), groupId()
bool QFileInfo::permission ( int  permissionSpec) const
bool QFileInfo::permission ( int  permissionSpec) const

Tests for file permissions. The permissionSpec argument can be several flags of type PermissionSpec OR-ed together to check for permission combinations.

On systems where files do not have permissions this function always returns TRUE.

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" );
Ver también:
isReadable(), isWritable(), isExecutable()

Tests for file permissions. The permissionSpec argument can be several flags of type PermissionSpec OR-ed together to check for permission combinations.

On systems where files do not have permissions this function always returns TRUE.

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!" );
Ver también:
isReadable(), isWritable(), isExecutable()
QString QFileInfo::readLink ( ) const
QString QFileInfo::readLink ( ) const

Returns the name a symlink (or shortcut on Windows) points to, or a QString::null 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.

Ver también:
exists(), isSymLink(), isDir(), isFile()

Returns the name a symlink (or shortcut on Windows) points to, or a null QString 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.

Ver también:
exists(), isSymLink(), isDir(), isFile()
void QFileInfo::refresh ( ) const
void QFileInfo::refresh ( ) const

Refreshes the information about the file, i.e. reads in information from the file system the next time a cached property is fetched.

Ver también:
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 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.

Ver también:
refresh(), caching()
void QFileInfo::setCaching ( bool  )
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"
Ver también:
isRelative(), QDir::setCurrent(), QDir::isRelativePath()
void QFileInfo::setFile ( const QDir d,
const QString fileName 
)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. 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.

Ver también:
isRelative()
void QFileInfo::setFile ( const QDir ,
const QString fileName 
)
void QFileInfo::setFile ( const QFile file)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. 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.

Ver también:
isRelative()
void QFileInfo::setFile ( const QString file)
void QFileInfo::setFile ( const QFile )
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.

uint QFileInfo::size ( ) const

Documentación de las funciones relacionadas y clases amigas

QDeepCopy< QFileInfo > [friend]

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'