|
|
Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QFileInfo class provides system-independent file information. More...
All the functions in this class are reentrant when Qt is built with thread support.
#include <qfileinfo.h>
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.
See also Input/Output and Networking.
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.
Warning: 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().
Warning: Some functions might behave in a counter-intuitive way if file has a trailing directory separator.
See also setFile(), isRelative(), QDir::setCurrent(), and QDir::isRelativePath().
If the file has a relative path, the QFileInfo will also have a relative path.
See also isRelative().
If d has a relative path, the QFileInfo will also have a relative path.
See also isRelative().
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).
See also isRelative() and filePath().
Examples: biff/biff.cpp and fileiconview/qfileiconview.cpp.
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"
See also fileName() and extension().
Returns TRUE if caching is enabled; otherwise returns FALSE.
See also setCaching() and refresh().
If it is already absolute, nothing is done.
See also filePath() and isRelative().
On platforms where this information is not available, returns the same as lastModified().
See also lastModified() and lastRead().
If the QFileInfo is relative and absPath is FALSE, the QDir will be relative; otherwise it will be absolute.
See also dirPath(), filePath(), fileName(), and isRelative().
Example: fileiconview/qfileiconview.cpp.
If absPath is TRUE an absolute path is returned.
See also dir(), filePath(), fileName(), and isRelative().
Example: fileiconview/qfileiconview.cpp.
Examples: biff/biff.cpp, distributor/distributor.ui.h, and i18n/main.cpp.
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"
See also fileName() and baseName().
Example: qdir/qdir.cpp.
Example:
QFileInfo fi( "/tmp/archive.tar.gz" ); QString name = fi.fileName(); // name = "archive.tar.gz"
See also isRelative(), filePath(), baseName(), and extension().
Examples: dirview/dirview.cpp, fileiconview/qfileiconview.cpp, and network/ftpclient/ftpmainwindow.ui.h.
See also isRelative() and absFilePath().
Examples: dirview/main.cpp and fileiconview/qfileiconview.cpp.
This function can be time consuming under Unix (in the order of milliseconds).
See also groupId(), owner(), and ownerId().
On Windows and on systems where files do not have groups this function always returns (uint) -2.
See also group(), owner(), and ownerId().
See also isFile() and isSymLink().
Examples: dirview/dirview.cpp and fileiconview/qfileiconview.cpp.
See also isReadable(), isWritable(), and permission().
See also isDir() and isSymLink().
Examples: dirview/dirview.cpp, distributor/distributor.ui.h, fileiconview/qfileiconview.cpp, and qdir/qdir.cpp.
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.
See also isWritable(), isExecutable(), and permission().
Example: distributor/distributor.ui.h.
See also isFile(), isDir(), and readLink().
Examples: dirview/dirview.cpp, distributor/distributor.ui.h, and fileiconview/qfileiconview.cpp.
See also isReadable(), isExecutable(), and permission().
Example: distributor/distributor.ui.h.
See also created() and lastRead().
Example: biff/biff.cpp.
On platforms where this information is not available, returns the same as lastModified().
See also created() and lastModified().
Example: biff/biff.cpp.
This function can be time consuming under Unix (in the order of milliseconds).
See also ownerId(), group(), and groupId().
On Windows and on systems where files do not have owners this function returns ((uint) -2).
See also owner(), group(), and groupId().
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" );
See also isReadable(), isWritable(), and isExecutable().
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.
See also exists(), isSymLink(), isDir(), and isFile().
See also setCaching().
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.
See also refresh() and caching().
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"
See also isRelative(), QDir::setCurrent(), and QDir::isRelativePath().
Example: biff/biff.cpp.
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.
See also isRelative().
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.
See also isRelative().
Example: qdir/qdir.cpp.
This file is part of the Qt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.
Copyright © 2007 Trolltech | Trademarks | Qt 3.3.8
|