|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QFileInfo
public class QFileInfo
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.
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:
QFileInfo info1 = new QFileInfo("/home/bob/bin/untabify"); info1.isSymLink(); // returns true info1.absoluteFilePath(); // returns "/home/bob/bin/untabify" info1.size(); // returns 56201 info1.symLinkTarget(); // returns "/opt/pretty++/bin/untabify" QFileInfo info2 = new QFileInfo(info1.symLinkTarget()); info1.isSymLink(); // returns false info1.absoluteFilePath(); // returns "/opt/pretty++/bin/untabify" info1.size(); // returns 56201On 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: QFileInfo info1 = new QFileInfo("C:\\Documents and Settings\\Bob\\untabify.lnk"); info1.isSymLink(); // returns true info1.absoluteFilePath(); // returns "C:/Documents and Settings/Bob/untabify.lnk" info1.size(); // returns 743 info1.symLinkTarget(); // returns "C:/Pretty++/untabify" QFileInfo info2 = new QFileInfo(info1.symLinkTarget()); info1.isSymLink(); // returns false info1.absoluteFilePath(); // returns "C:/Pretty++/untabify" info1.size(); // returns 63942Elements 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.Performance Issues
Some of QFileInfo
's functions query the file system, but for performance reasons, some functions 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()
function, however, can work on the file name directly, and so it is faster.
Note: To speed up performance, QFileInfo
caches information about the file.
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).
QDir
, and QFile
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Constructor Summary | |
---|---|
QFileInfo()
Constructs an empty QFileInfo object. |
|
QFileInfo(QDir dir,
java.lang.String file)
Constructs a new QFileInfo that gives information about the given file in the directory dir. |
|
QFileInfo(QFile file)
Constructs a new QFileInfo that gives information about file file. |
|
QFileInfo(QFileInfo fileinfo)
Constructs a new QFileInfo that is a copy of the given fileinfo. |
|
QFileInfo(java.lang.String file)
Constructs a new QFileInfo that gives information about the given file. |
Method Summary | |
---|---|
QDir |
absoluteDir()
Returns the file's absolute path as a QDir object. |
java.lang.String |
absoluteFilePath()
Returns the absolute path including the file name. |
java.lang.String |
absolutePath()
Returns the file's path absolute path. |
java.lang.String |
baseName()
Returns the base name of the file without the path. |
java.lang.String |
bundleName()
Returns the name of the bundle. |
boolean |
caching()
Returns true if caching is enabled; otherwise returns false. |
java.lang.String |
canonicalFilePath()
Returns the canonical path, i.e. |
java.lang.String |
canonicalPath()
Returns the canonical path, i.e. |
QFileInfo |
clone()
This method is reimplemented for internal reasons |
java.lang.String |
completeBaseName()
Returns the complete base name of the file without the path. |
java.lang.String |
completeSuffix()
Returns the complete suffix of the file. |
QDateTime |
created()
Returns the date and time when the file was created. |
QDir |
dir()
Returns the path of the object's parent directory as a QDir object. |
boolean |
exists()
Returns true if the file exists; otherwise returns false. |
java.lang.String |
fileName()
Returns the name of the file, excluding the path. |
java.lang.String |
filePath()
Returns the file name, including the path (which may be absolute or relative). |
static QFileInfo |
fromNativePointer(QNativePointer nativePointer)
|
java.lang.String |
group()
Returns the group of the file. |
int |
groupId()
Returns the id of the group the file belongs to. |
boolean |
isAbsolute()
Returns true if the file path name is absolute, otherwise returns false if the path is relative. |
boolean |
isBundle()
Returns true if this object points to a bundle or to a symbolic link to a bundle on Mac OS X; otherwise returns false. |
boolean |
isDir()
Returns true if this object points to a directory or to a symbolic link to a directory; otherwise returns false. |
boolean |
isExecutable()
Returns true if the file is executable; otherwise returns false. |
boolean |
isFile()
Returns true if this object points to a file or to a symbolic link to a file. |
boolean |
isHidden()
Returns true if this is a `hidden' file; otherwise returns false. |
boolean |
isReadable()
Returns true if the user can read the file; otherwise returns false. |
boolean |
isRelative()
Returns true if the file path name is relative, otherwise returns false if the path is absolute (e.g. |
boolean |
isRoot()
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. |
boolean |
isSymLink()
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise returns false. |
boolean |
isWritable()
Returns true if the user can write to the file; otherwise returns false. |
QDateTime |
lastModified()
Returns the date and time when the file was last modified. |
QDateTime |
lastRead()
Returns the date and time when the file was last read (accessed). |
boolean |
makeAbsolute()
Converts the file's path to an absolute path if it is not already in that form. |
static QNativePointer |
nativePointerArray(QFileInfo[] array)
|
java.lang.String |
owner()
Returns the owner of the file. |
int |
ownerId()
Returns the id of the owner of the file. |
java.lang.String |
path()
Returns the file's path. |
boolean |
permission(QFile.Permission[] permissions)
Tests for file permissions. |
boolean |
permission(QFile.Permissions permissions)
Tests for file permissions. |
QFile.Permissions |
permissions()
Returns the complete OR-ed together combination of QFile.:Permissions for the file. |
void |
refresh()
Refreshes the information about the file, i.e. |
void |
setCaching(boolean on)
If enable is true, enables caching of file information. |
void |
setFile(QDir dir,
java.lang.String file)
Sets the file that the QFileInfo provides information about to file in directory dir. |
void |
setFile(QFile file)
Sets the file that the QFileInfo provides information about to file. |
void |
setFile(java.lang.String file)
Sets the file that the QFileInfo provides information about to file. |
long |
size()
Returns the file size in bytes. |
java.lang.String |
suffix()
Returns the suffix of the file. |
java.lang.String |
symLinkTarget()
Returns the absolute path to the file or directory a symlink (or shortcut on Windows) points to, or a an empty string if the object isn't a symbolic link. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QFileInfo()
QFileInfo
object. Note that an empty QFileInfo
object contain no file reference.
setFile()
.
public QFileInfo(QDir dir, java.lang.String file)
QFileInfo
that gives information about the given file in the directory dir. If dir has a relative path, the QFileInfo
will also have a relative path.
isRelative()
.
public QFileInfo(QFile file)
QFileInfo
that gives information about file file. If the file has a relative path, the QFileInfo
will also have a relative path.
isRelative()
.
public QFileInfo(QFileInfo fileinfo)
QFileInfo
that is a copy of the given fileinfo.
public QFileInfo(java.lang.String file)
QFileInfo
that gives information about the given file. The file can also include an absolute or relative path. setFile()
, isRelative()
, QDir::setCurrent()
, and QDir::isRelativePath()
.
Method Detail |
---|
public final QDir absoluteDir()
QDir
object. filePath()
, fileName()
, isRelative()
, and dir()
.
public final java.lang.String absoluteFilePath()
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::currentPath()
.
This function can be time consuming under Unix (in the order of milliseconds).
isRelative()
, and filePath()
.
public final java.lang.String absolutePath()
dir()
, filePath()
, fileName()
, isRelative()
, and path()
.
public final java.lang.String baseName()
The base name consists of all characters in the file up to (but not including) the first '.' character.
Example:
QFileInfo fi = new QFileInfo("/tmp/archive.tar.gz"); String base = fi.baseName(); // base = "archive"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").
fileName()
, suffix()
, completeSuffix()
, and completeBaseName()
.
public final java.lang.String bundleName()
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.
Example:
QFileInfo fi = new QFileInfo("/Applications/Safari.app"); String bundle = fi.bundleName(); // name = "Safari"
isBundle()
, filePath()
, baseName()
, and extension().
public final boolean caching()
setCaching()
, and refresh()
.
public final java.lang.String canonicalFilePath()
On systems that do not have symbolic links this function will always return the same string that absoluteFilePath()
returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalFilePath()
returns an empty string.
filePath()
, and absoluteFilePath()
.
public final java.lang.String canonicalPath()
On systems that do not have symbolic links this function will always return the same string that absolutePath()
returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalPath()
returns an empty string.
absolutePath()
.
public final java.lang.String completeBaseName()
The complete base name consists of all characters in the file up to (but not including) the last '.' character.
Example:
QFileInfo fi = new QFileInfo("/tmp/archive.tar.gz"); String base = fi.completeBaseName(); // base = "archive.tar"
fileName()
, suffix()
, completeSuffix()
, and baseName()
.
public final java.lang.String completeSuffix()
The complete suffix consists of all characters in the file after (but not including) the first '.'.
Example:
QFileInfo fi = new QFileInfo("/tmp/archive.tar.gz"); String ext = fi.completeSuffix(); // ext = "tar.gz"
fileName()
, suffix()
, baseName()
, and completeBaseName()
.
public final QDateTime created()
On most Unix systems, this function returns the time of the last status change. A status change occurs when the file is created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions).
If neither creation time nor "last status change" time are not available, returns the same as lastModified()
.
lastModified()
, and lastRead()
.
public final QDir dir()
QDir
object. Note: The QDir
returned always corresponds to the object's parent directory, even if the QFileInfo
represents a directory.
For each of the follwing, dir()
returns a QDir
for "~/examples/191697".
The following code example is written in c++.
QFileInfo fileInfo1("~/examples/191697/."); QFileInfo fileInfo2("~/examples/191697/.."); QFileInfo fileInfo3("~/examples/191697/main.cpp");For each of the follwing,
dir()
returns a QDir
for ".".QFileInfo fileInfo4("."); QFileInfo fileInfo5(".."); QFileInfo fileInfo6("main.cpp");
filePath()
, fileName()
, isRelative()
, and absoluteDir()
.
public final boolean exists()
public final java.lang.String fileName()
Example:
QFileInfo fi = new QFileInfo("/tmp/archive.tar.gz"); String name = fi.fileName(); // name = "archive.tar.gz"
isRelative()
, filePath()
, baseName()
, and extension().
public final java.lang.String filePath()
isRelative()
, and absoluteFilePath()
.
public final java.lang.String group()
This function can be time consuming under Unix (in the order of milliseconds).
groupId()
, owner()
, and ownerId()
.
public final int groupId()
On Windows and on systems where files do not have groups this function always returns (uint) -2.
group()
, owner()
, and ownerId()
.
public final boolean isAbsolute()
isRelative()
.
public final boolean isBundle()
isDir()
, isSymLink()
, and isFile()
.
public final boolean isDir()
isFile()
, isSymLink()
, and isBundle()
.
public final boolean isExecutable()
isReadable()
, isWritable()
, and permission()
.
public final boolean isFile()
isDir()
, isSymLink()
, and isBundle()
.
public final boolean isHidden()
Note: This function returns true for the special entries "." and ".." on Unix, even though QDir::entryList
threats them as shown.
public final boolean isReadable()
isWritable()
, isExecutable()
, and permission()
.
public final boolean isRelative()
isAbsolute()
.
public final boolean isRoot()
public final boolean isSymLink()
On Unix (including Mac OS X), opening a symlink effectively opens the link's target
. On Windows, it opens the .lnk file itself.
Example:
QFileInfo info = new QFileInfo(fileName); if (info.isSymLink()) fileName = info.symLinkTarget();
isFile()
, isDir()
, and symLinkTarget()
.
public final boolean isWritable()
isReadable()
, isExecutable()
, and permission()
.
public final QDateTime lastModified()
created()
, and lastRead()
.
public final QDateTime lastRead()
On platforms where this information is not available, returns the same as lastModified()
.
created()
, and lastModified()
.
public final boolean makeAbsolute()
filePath()
, and isRelative()
.
public final java.lang.String owner()
This function can be time consuming under Unix (in the order of milliseconds).
ownerId()
, group()
, and groupId()
.
public final int ownerId()
On Windows and on systems where files do not have owners this function returns ((uint) -2).
owner()
, group()
, and groupId()
.
public final java.lang.String path()
dir()
, filePath()
, fileName()
, isRelative()
, and absolutePath()
.
public final boolean permission(QFile.Permission[] permissions)
On systems where files do not have permissions this function always returns true.
Example:
QFileInfo fi = new QFileInfo("/tmp/archive.tar.gz"); QFile.Permissions permissions1 = new QFile.Permissions(QFile.Permission.WriteUser, QFile.Permission.ReadGroup); if (fi.permission(permissions1)) System.out.println("I can change the file; my group can read the file"); QFile.Permissions permissions2 = new QFile.Permissions(QFile.Permission.WriteGroup, QFile.Permission.WriteOther); if (fi.permission(permissions2)) System.out.println("The group or others can change the file");
isReadable()
, isWritable()
, and isExecutable()
.
public final boolean permission(QFile.Permissions permissions)
On systems where files do not have permissions this function always returns true.
Example:
QFileInfo fi = new QFileInfo("/tmp/archive.tar.gz"); QFile.Permissions permissions1 = new QFile.Permissions(QFile.Permission.WriteUser, QFile.Permission.ReadGroup); if (fi.permission(permissions1)) System.out.println("I can change the file; my group can read the file"); QFile.Permissions permissions2 = new QFile.Permissions(QFile.Permission.WriteGroup, QFile.Permission.WriteOther); if (fi.permission(permissions2)) System.out.println("The group or others can change the file");
isReadable()
, isWritable()
, and isExecutable()
.
public final QFile.Permissions permissions()
public final void refresh()
Note: On Windows CE, there might be a delay for the file system driver to detect changes on the file.
public final void setCaching(boolean on)
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.
refresh()
, and caching()
.
public final void setFile(QDir dir, java.lang.String file)
QFileInfo
provides information about to file in directory dir. If file includes a relative path, the QFileInfo
will also have a relative path.
isRelative()
.
public final void setFile(QFile file)
QFileInfo
provides information about to file. If file includes a relative path, the QFileInfo
will also have a relative path.
isRelative()
.
public final void setFile(java.lang.String file)
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:
String absolute = "/local/bin"; String relative = "local/bin"; QFileInfo absFile = new QFileInfo(absolute); QFileInfo relFile = new QFileInfo(relative); QDir.setCurrent(QDir.rootPath()); // 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"
isFile()
, isRelative()
, QDir::setCurrent()
, and QDir::isRelativePath()
.
public final long size()
exists()
.
public final java.lang.String suffix()
The suffix consists of all characters in the file after (but not including) the last '.'.
Example:
QFileInfo fi = new QFileInfo("/tmp/archive.tar.gz"); String ext = fi.suffix(); // ext = "gz"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").
fileName()
, completeSuffix()
, baseName()
, and completeBaseName()
.
public final java.lang.String symLinkTarget()
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.
exists()
, isSymLink()
, isDir()
, and isFile()
.
public static QFileInfo fromNativePointer(QNativePointer nativePointer)
public static QNativePointer nativePointerArray(QFileInfo[] array)
public QFileInfo clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |