The QFileInfo class provides system-independent file information. More...
#include <qfileinfo.h>
Public Types | |
enum | PermissionSpec { ReadUser = 0400, WriteUser = 0200, ExeUser = 0100, ReadGroup = 0040, WriteGroup = 0020, ExeGroup = 0010, ReadOther = 0004, WriteOther = 0002, ExeOther = 0001 } |
Private Member Functions | |
void | doStat () const |
Static Private Member Functions | |
static void | slashify (QString &) |
static void | makeAbs (QString &) |
Private Attributes | |
QString | fn |
QFileInfoCache * | fic |
bool | cache |
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 a symbolic link. Its size and last modified/read times are also available.
To speed up performance QFileInfo caches information about the file. Since 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 would rather like a QFileInfo to access the file system every time you request information from it, you can call the function setCaching( FALSE ).
A QFileInfo can point to a file using either a relative or an absolute file path. Absolute file paths begin with the directory separator ('/') or a drive specification (not applicable to UNIX). Relative file names begin with a directory name or a file name and specify a path relative to the current 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 if a QFileInfo is using a relative or an absolute file path. You can call the function convertToAbs() to convert a relative QFileInfo to an absolute one.
If you need to read and traverse directories, see the QDir class.
Definition at line 51 of file qfileinfo.h.
Enumerator | |
---|---|
ReadUser | |
WriteUser | |
ExeUser | |
ReadGroup | |
WriteGroup | |
ExeGroup | |
ReadOther | |
WriteOther | |
ExeOther |
Definition at line 54 of file qfileinfo.h.
QFileInfo::QFileInfo | ( | ) |
QFileInfo::QFileInfo | ( | const QString & | file | ) |
Constructs a new QFileInfo that gives information about the given file. The string given can be an absolute or a relative file path.
Definition at line 97 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | const QFile & | file | ) |
Constructs a new QFileInfo that gives information about file.
If the file has a relative path, the QFileInfo will also have one.
Definition at line 113 of file qfileinfo.cpp.
Constructs a new QFileInfo that gives information about the file named fileName in the directory d.
If the directory has a relative path, the QFileInfo will also have one.
Definition at line 130 of file qfileinfo.cpp.
QFileInfo::QFileInfo | ( | const QFileInfo & | fi | ) |
Constructs a new QFileInfo that is a copy of fi.
Definition at line 142 of file qfileinfo.cpp.
QFileInfo::~QFileInfo | ( | ) |
Destructs the QFileInfo.
Definition at line 158 of file qfileinfo.cpp.
QString QFileInfo::absFilePath | ( | ) | const |
Returns the absolute path name.
The absolute path name is the file name including the absolute path. If the QFileInfo is absolute (i.e. not relative) this function will return the same string as filePath().
Note that this function can be time-consuming under UNIX. (in the order of milliseconds on a 486 DX2/66 running Linux).
Definition at line 410 of file qfileinfo_unix.cpp.
QString QFileInfo::baseName | ( | ) | const |
Returns the base name of the file.
The base name consists of all characters in the file name up to (but not including) the first '.' character. The path is not included.
Definition at line 341 of file qfileinfo.cpp.
|
inline |
Returns TRUE if caching is enabled.
Definition at line 132 of file qfileinfo.h.
bool QFileInfo::convertToAbs | ( | ) |
Converts the file path name to an absolute path.
If it is already absolute nothing is done.
Definition at line 452 of file qfileinfo.cpp.
Returns the directory path of the file.
If the QFileInfo is relative and absPath is FALSE, the QDir will be relative, otherwise it will be absolute.
Definition at line 393 of file qfileinfo.cpp.
Returns the directory path of the file.
If absPath is TRUE an absolute path is always returned.
Definition at line 358 of file qfileinfo_unix.cpp.
|
private |
Definition at line 324 of file qfileinfo_unix.cpp.
bool QFileInfo::exists | ( | ) | const |
Returns TRUE if the file pointed to exists, otherwise FALSE.
Definition at line 265 of file qfileinfo.cpp.
Returns the extension name of the file.
If complete is TRUE (the default), extension() returns the string of all characters in the file name after (but not including) the first '.' character. For a file named "archive.tar.gz" this returns "tar.gz".
If complete is FALSE, extension() returns the string of all characters in the file name after (but not including) the last '.' character. For a file named "archive.tar.gz" this returns "gz".
Definition at line 374 of file qfileinfo.cpp.
QString QFileInfo::fileName | ( | ) | const |
Returns the name of the file, the file path is not included.
Definition at line 387 of file qfileinfo_unix.cpp.
QString QFileInfo::filePath | ( | ) | const |
Returns the name, i.e. the file name including the path (which can be absolute or relative).
Definition at line 321 of file qfileinfo.cpp.
QString QFileInfo::group | ( | ) | const |
Returns the group the file belongs to.
On systems where files do not have groups this function always returns 0.
Note that this function can be time-consuming under UNIX (in the order of milliseconds on a 486 DX2/66 running Linux).
Definition at line 187 of file qfileinfo_unix.cpp.
uint QFileInfo::groupId | ( | ) | const |
Returns the id of the group the file belongs to.
On systems where files do not have groups this function always returns ((uind) -2).
Definition at line 204 of file qfileinfo_unix.cpp.
bool QFileInfo::isDir | ( | ) | const |
Returns TRUE if we are pointing to a directory or a symbolic link to a directory.
Definition at line 88 of file qfileinfo_unix.cpp.
bool QFileInfo::isExecutable | ( | ) | const |
Returns TRUE if the file is executable.
Definition at line 425 of file qfileinfo.cpp.
bool QFileInfo::isFile | ( | ) | const |
Returns TRUE if we are pointing to a real file.
Definition at line 75 of file qfileinfo_unix.cpp.
bool QFileInfo::isReadable | ( | ) | const |
Returns TRUE if the file is readable.
Definition at line 405 of file qfileinfo.cpp.
bool QFileInfo::isRelative | ( | ) | const |
Returns TRUE if the file path name is relative to the current directory, FALSE if the path is absolute (e.g. under UNIX a path is relative if it does not start with a '/').
According to Einstein this function should always return TRUE.
Definition at line 439 of file qfileinfo.cpp.
bool QFileInfo::isSymLink | ( | ) | const |
Returns TRUE if we are pointing to a symbolic link.
Definition at line 100 of file qfileinfo_unix.cpp.
bool QFileInfo::isWritable | ( | ) | const |
Returns TRUE if the file is writable.
Definition at line 415 of file qfileinfo.cpp.
QDateTime QFileInfo::lastModified | ( | ) | const |
Returns the date and time when the file was last modified.
Definition at line 294 of file qfileinfo_unix.cpp.
QDateTime QFileInfo::lastRead | ( | ) | const |
Returns the date and time when the file was last read (accessed).
On systems that do not support last read times, the modification time is returned.
Definition at line 313 of file qfileinfo_unix.cpp.
|
staticprivate |
Definition at line 64 of file qfileinfo_unix.cpp.
Makes a copy of fi and assigns it to this QFileInfo.
Definition at line 168 of file qfileinfo.cpp.
QString QFileInfo::owner | ( | ) | const |
Returns the owner of the file.
On systems where files do not have owners this function returns 0.
Note that this function can be time-consuming under UNIX. (in the order of milliseconds on a 486 DX2/66 running Linux).
Returns the owner of the file.
On systems where files do not have owners this function returns a null string.
Note that this function can be time-consuming under UNIX. (in the order of milliseconds on a 486 DX2/66 running Linux).
Definition at line 150 of file qfileinfo_unix.cpp.
uint QFileInfo::ownerId | ( | ) | const |
Returns the id of the owner of the file.
On systems where files do not have owners this function returns ((uint) -2).
Definition at line 166 of file qfileinfo_unix.cpp.
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.
Definition at line 236 of file qfileinfo_unix.cpp.
QString QFileInfo::readLink | ( | ) | const |
Returns the name a symlink points to, or a null QString if the object does not refer to 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.
Definition at line 119 of file qfileinfo_unix.cpp.
void QFileInfo::refresh | ( | ) | const |
Refresh the information about the file, i.e. read in information from the file system the next time a cached property is fetched.
Definition at line 277 of file qfileinfo.cpp.
void QFileInfo::setCaching | ( | bool | enable | ) |
Enables caching of file information if enable is TRUE, or disables it if enable is FALSE.
When caching is enabled, QFileInfo reads the file information the first time
Caching is enabled by default.
Definition at line 302 of file qfileinfo.cpp.
void QFileInfo::setFile | ( | const QString & | file | ) |
Sets the file to obtain information about.
The string given can be an absolute or a relative file path. Absolute file paths begin with the directory separator (e.g. '/' under UNIX) or a drive specification (not applicable to UNIX). Relative file names begin with a directory name or a file name and specify a path relative to the current directory.
Definition at line 219 of file qfileinfo.cpp.
void QFileInfo::setFile | ( | const QFile & | file | ) |
Sets the file to obtain information about.
If the file has a relative path, the QFileInfo will also have one.
Definition at line 235 of file qfileinfo.cpp.
Sets the file to obtains information about to fileName in the directory d.
If the directory has a relative path, the QFileInfo will also have one.
Definition at line 252 of file qfileinfo.cpp.
uint QFileInfo::size | ( | ) | const |
Returns the file size in bytes, or 0 if the file does not exist if the size cannot be fetched.
Definition at line 278 of file qfileinfo_unix.cpp.
|
staticprivate |
Definition at line 58 of file qfileinfo_unix.cpp.
|
private |
Definition at line 128 of file qfileinfo.h.
|
private |
Definition at line 127 of file qfileinfo.h.
|
private |
Definition at line 126 of file qfileinfo.h.