CopperSpice API
1.9.2
|
The QFileInfo class provides information about a given file. More...
Public Methods | |
QFileInfo () | |
QFileInfo (const QDir &dir, const QString &file) | |
QFileInfo (const QFile &file) | |
QFileInfo (const QFileInfo &fileinfo) | |
QFileInfo (const QString &file) | |
~QFileInfo () | |
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 |
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 | isNativePath () 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 |
QFileInfo & | operator= (const QFileInfo &fileinfo) |
QFileInfo & | operator= (QFileInfo &&other) |
bool | operator== (const QFileInfo &fileinfo) const |
QString | owner () const |
uint | ownerId () const |
QString | path () const |
bool | permission (QFile::Permissions permissions) const |
QFile::Permissions | permissions () const |
QString | readLink () const |
void | refresh () |
void | setCaching (bool enable) |
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 |
Related Functions | |
These are not member functions | |
QFileInfoList | |
The QFileInfo class provides information about a given file. This information includes the file name, permissions, path in the file system, whether it is a symbolic link, etc. QFileInfo can also be used to obtain information about a CopperSpice 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 method isRelative() to check whether a QFileInfo is using a relative or an absolute file path. You can call the method makeAbsolute() to convert a relative QFileInfo's path to an absolute path.
The file for a QFileInfo object is set in the constructor or by calling setFile(). Call exists() to verify if the file is present and call size() to get its size. The file's type is obtained with isFile(), isDir() and isSymLink().
On Unix and Mac OS X, the symlink has the same size as the file it points to. Opening a symlink using QFile effectively opens the link's target.
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.
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 CopperSpice classes, will not have a trailing file separator. If you want to use trailing separators in your file info objects, 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() method.
Some of the methods in this class will query the file system. For performance reasons, some methods only operate on the file name itself. For example, to return the absolute path of a relative file name, absolutePath() has to query the file system. The path() method can work on the file name directly, and so it is faster.
To speed up performance QFileInfo caches information about the file. Since files can be changed by other users, programs, or other parts of the same program, the refresh() method can be called to refresh the file information. 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).
QFileInfo::QFileInfo | ( | ) |
Constructs an empty QFileInfo object.
QFileInfo::QFileInfo | ( | const QString & | file | ) |
Constructs a new QFileInfo which contains information about the given file. The file can also include an absolute or relative path.
QFileInfo::QFileInfo | ( | const QFile & | file | ) |
Constructs a new QFileInfo using the given file. If the file has a relative path the QFileInfo will also have a relative path.
Constructs a new QFileInfo using the given file from the given dir. If dir has a relative path, the QFileInfo will also have a relative path. If file is an absolute path then the directory specified by dir will be disregarded.
QFileInfo::QFileInfo | ( | const QFileInfo & | fileinfo | ) |
Constructs a new QFileInfo that is a copy of the given fileinfo.
QFileInfo::~QFileInfo | ( | ) |
Destroys the QFileInfo and frees its resources.
QDir QFileInfo::absoluteDir | ( | ) | const |
Returns the file's absolute path as a QDir object.
QString QFileInfo::absoluteFilePath | ( | ) | const |
Returns an absolute path including the file name. If the QFileInfo is empty it returns QDir::currentPath(). Returns the same as filePath(), unless isRelative() is true. In contrast to canonicalFilePath(), symbolic links or redundant "." or ".." elements are not necessarily removed.
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/'. QFileInfo will uppercase drive letters however QDir does not do this.
QString QFileInfo::absolutePath | ( | ) | const |
Returns the absolute path for this file which does not include the file name. In contrast to the method canonicalPath(), symbolic links or redundant "." or ".." elements are not necessarily removed. If the QFileInfo object was created with an empty QString the behavior of this method is undefined.
On Unix the absolute path 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/'.
QString QFileInfo::baseName | ( | ) | const |
Returns the base name of the file without the path. The base name consists of all characters in the file up to (but not including) the first '.' character.
The base name of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").
QString QFileInfo::bundleName | ( | ) | const |
Returns the name of the bundle. On Mac OS X this returns the proper localized name for a bundle if the path isBundle(). On all other platforms an empty QString is returned.
bool QFileInfo::caching | ( | ) | const |
Returns true if caching is enabled, otherwise returns false.
QString QFileInfo::canonicalFilePath | ( | ) | const |
Returns the canonical path including the file name. This is an absolute path without symbolic links or redundant "." or ".." elements. If the file does not exist, canonicalFilePath() returns an empty string.
QString QFileInfo::canonicalPath | ( | ) | const |
Returns the file's path canonical path excluding the file name. This is an absolute path without symbolic links or redundant "." or ".." elements.
If the file does not exist, canonicalPath() returns an empty string.
QString QFileInfo::completeBaseName | ( | ) | const |
Returns the complete base name of the file without the path. The complete base name consists of all characters in the file up to but not including the last '.' character.
QString QFileInfo::completeSuffix | ( | ) | const |
Returns the complete suffix of the file. The complete suffix consists of all characters in the file after but not including the first '.'.
QDateTime QFileInfo::created | ( | ) | const |
Returns the date and time when the file was created.
On most Unix systems this method returns the time of the last status change. A status change occurs when the file is created but it also occurs whenever the user changes meta data file. For example, when the file permissions are changed.
If neither creation time nor "last status change" time are available, this method returns the same as calling lastModified().
QDir QFileInfo::dir | ( | ) | const |
Returns the path of the object's parent directory as a QDir object. The return value always corresponds to the object's parent directory, even if the QFileInfo represents a directory.
For each of the following, calling dir() returns a QDir for "~/examples/191697".
For each of the following calling dir() returns a QDir for ".".
bool QFileInfo::exists | ( | ) | const |
Returns true if the file exists, otherwise returns false.
QString QFileInfo::fileName | ( | ) | const |
Returns the name of the file, excluding the path. If this QFileInfo object is given a path ending in a slash, the name of the file is considered empty.
QString QFileInfo::filePath | ( | ) | const |
Returns the file name, including the path (which may be absolute or relative).
QString QFileInfo::group | ( | ) | const |
uint QFileInfo::groupId | ( | ) | const |
|
inline |
Returns true if the file path name is absolute, otherwise returns false if the path is relative.
bool QFileInfo::isBundle | ( | ) | const |
Returns true if this object points to a bundle or to a symbolic link to a bundle on Mac OS X, otherwise returns false.
bool QFileInfo::isDir | ( | ) | const |
Returns true if this object points to a directory or to a symbolic link to a directory, otherwise returns false.
bool QFileInfo::isExecutable | ( | ) | const |
Returns true if the file is executable, otherwise returns false.
bool QFileInfo::isFile | ( | ) | const |
Returns true if this object points to a file or to a symbolic link to a file. Returns false if the object points to something which is not a file, such as a directory.
bool QFileInfo::isHidden | ( | ) | const |
Returns true if this is a ‘hidden’ file, otherwise returns false.
bool QFileInfo::isNativePath | ( | ) | const |
Returns true if the file path can be used directly with native APIs. Returns false if the file is otherwise supported by a virtual file system inside CopperSpice, such as the Resource System.
bool QFileInfo::isReadable | ( | ) | const |
Returns true if the user can read the file, otherwise returns false.
bool QFileInfo::isRelative | ( | ) | const |
Returns true if the file path name is relative, otherwise returns false if the path is absolute (e.g. under Unix a path is absolute if it begins with a "/").
bool QFileInfo::isRoot | ( | ) | const |
Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory, otherwise returns false.
bool QFileInfo::isSymLink | ( | ) | const |
Returns true if this object points to a symbolic link (or to a shortcut on Windows), otherwise returns false. On Unix and Mac OS X, opening a symlink effectively opens the link's target. On Windows, it opens the .lnk
file itself.
bool QFileInfo::isWritable | ( | ) | const |
Returns true if the user can write to the file, otherwise returns false.
QDateTime QFileInfo::lastModified | ( | ) | const |
Returns the date and time when the file was last modified.
QDateTime QFileInfo::lastRead | ( | ) | const |
Returns the date and time when the file was last read or accessed. On platforms where this information is not available, returns the same as lastModified().
bool QFileInfo::makeAbsolute | ( | ) |
Converts the file's path to an absolute path if it is not already in that form. Returns true to indicate that the path was converted, otherwise returns false to indicate that the path was already absolute.
|
inline |
Returns true if this QFileInfo object refers to a different file than the one specified by fileinfo, otherwise returns false.
QFileInfo & QFileInfo::operator= | ( | const QFileInfo & | fileinfo | ) |
Copy assigns from other and returns a reference to this object.
|
inline |
Move assigns from other and returns a reference to this object.
bool QFileInfo::operator== | ( | const QFileInfo & | fileinfo | ) | const |
Returns true if this QFileInfo object refers to a file in the same location as fileinfo, otherwise returns false. The result of comparing two empty QFileInfo objects, containing no file references, is undefined.
QString QFileInfo::owner | ( | ) | const |
uint QFileInfo::ownerId | ( | ) | const |
QString QFileInfo::path | ( | ) | const |
Returns the file's path. This does not include the file name. If this QFileInfo object is given a path ending in a slash, the name of the file is considered empty and this method will return the entire path.
bool QFileInfo::permission | ( | QFile::Permissions | permissions | ) | const |
Tests for file permissions. The permissions argument can be several flags of type QFile::Permissions OR-ed together to check for permission combinations. On systems where files do not have permissions this method always returns true.
QFile::Permissions QFileInfo::permissions | ( | ) | const |
Returns the complete OR-ed together combination of QFile::Permissions for the file.
|
deprecated |
void QFileInfo::refresh | ( | ) |
Refreshes the information about the file and reads information directly from the file system the next time a cached property is fetched.
void QFileInfo::setCaching | ( | bool | enable | ) |
Sets the file that the QFileInfo provides information about to file in directory dir. If file includes a relative path, the QFileInfo will also have a relative path.
void QFileInfo::setFile | ( | const QFile & | file | ) |
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.
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.
qint64 QFileInfo::size | ( | ) | const |
Returns the file size in bytes. If the file does not exist or can not be fetched then 0 is returned.
QString QFileInfo::suffix | ( | ) | const |
Returns the suffix of the file. The suffix consists of all characters in the file after but not including the last '.'. The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").
|
inline |
Returns the absolute path to the file or directory a symlink (or shortcut on Windows) points to, or an empty string if the object is not a symbolic link. The name may not represent an actual file, since it is only a string. QFileInfo::exists() returns true if the symlink points to an existing file.
|
related |
Equivalent to QList<QFileInfo>.