|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QDir
public class QDir
The QDir
class provides access to directory structures and their contents. A QDir
is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system. It can also be used to access Qt's resource system.
Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.
A QDir
can point to a file using either a relative or an absolute path. Absolute paths begin with the directory separator (optionally preceded by 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.
Examples of absolute paths:
new QDir("/home/user/Documents"); new QDir("C:/Documents and Settings");On Windows, the second example above will be translated to C:\Documents and Settings when used to access files.
Examples of relative paths:
new QDir("images/landscape.png");You can use the
isRelative()
or isAbsolute()
functions to check if a QDir
is using a relative or an absolute file path. Call makeAbsolute()
to convert a relative QDir
to an absolute one.path()
function, and a new path set with the setPath()
function. The absolute path to a directory is found by calling absolutePath()
. The name of a directory is found using the dirName()
function. This typically returns the last element in the absolute path that specifies the location of the directory. However, it can also return "." if the QDir
represents the current directory.
new QDir("Documents/Letters/Applications").dirName(); // "Applications" new QDir().dirName(); // "."The path for a directory can also be changed with the
cd()
and cdUp()
functions, both of which operate like familiar shell commands. When cd()
is called with the name of an existing directory, the QDir
object changes directory so that it represents that directory instead. The cdUp()
function changes the directory of the QDir
object so that it refers to its parent directory; i.e. cd("..") is equivalent to cdUp()
. Directories can be created with mkdir()
, renamed with rename()
, and removed with rmdir()
.
You can test for the presence of a directory with a given name by using exists()
, and the properties of a directory can be tested with isReadable()
, isAbsolute()
, isRelative()
, and isRoot()
.
The refresh()
function re-reads the directory's data from disk.Files and Directory Contents
Directories contain a number of entries, representing files, directories, and symbolic links. The number of entries in a directory is returned by count()
. A string list of the names of all the entries in a directory can be obtained with entryList()
. If you need information about each entry, use entryInfoList()
to obtain a list of QFileInfo
objects.
Paths to files and directories within a directory can be constructed using filePath()
and absoluteFilePath()
. The filePath()
function returns a path to the specified file or directory relative to the path of the QDir
object; absoluteFilePath()
returns an absolute path to the specified file or directory. Neither of these functions checks for the existence of files or directory; they only construct paths.
QDir directory = new QDir("Documents/Letters"); String path = directory.filePath("contents.txt"); String absolutePath = directory.absoluteFilePath("contents.txt");Files can be removed by using the
remove()
function. Directories cannot be removed in the same way as files; use rmdir()
to remove them instead. It is possible to reduce the number of entries returned by entryList()
and entryInfoList()
by applying filters to a QDir
object. You can apply a name filter to specify a pattern with wildcards that file names need to match, an attribute filter that selects properties of entries and can distinguish between files and directories, and a sort order.
Name filters are lists of strings that are passed to setNameFilters()
. Attribute filters consist of a bitwise OR combination of Filters, and these are specified when calling setFilter()
. The sort order is specified using setSorting()
with a bitwise OR combination of SortFlags.
You can test to see if a filename matches a filter using the match()
function.
Filter and sort order flags may also be specified when calling entryList()
and entryInfoList()
in order to override previously defined behavior.The Current Directory and Other Special Paths
Access to some common directories is provided with a number of static functions that return QDir
objects. There are also corresponding functions for these that return strings:
QDir | ||
---|---|---|
current() | currentPath() | The application's working directory |
home() | homePath() | The user's home directory |
root() | rootPath() | The root directory |
temp() | tempPath() | The system's temporary directory |
setCurrent()
static function can also be used to set the application's working directory. If you want to find the directory containing the application's executable, see QCoreApplication::applicationDirPath()
.
The drives()
static function provides a list of root directories for each device that contains a filing system. On Unix systems this returns a list containing a single root directory "/"; on Windows the list will usually contain C:/, and possibly other drive letters such as D:/, depending on the configuration of the user's system.Path Manipulation and Strings
Paths containing "." elements that reference the current directory at that point in the path, ".." elements that reference the parent directory, and symbolic links can be reduced to a canonical form using the canonicalPath()
function.
Paths can also be simplified by using cleanPath()
to remove redundant "/" and ".." elements.
It is sometimes necessary to be able to show a path in the native representation for the user's platform. The static toNativeSeparators()
function returns a copy of the specified path in which each directory separator is replaced by the appropriate separator for the underlying operating system.Examples
Check if a directory exists:
QDir dir = new QDir("example");
if (!dir.exists())
System.err.println("Cannot find the example directory");
(We could also use the static convenience function QFile::exists()
.)
Traversing directories and reading a file:
QDir dir = QDir.root(); // "/" if (!dir.cd("tmp")) { // "/tmp" System.err.println("Cannot find the \"/tmp\" directory"); } else { QFile file = new QFile(dir.filePath("ex1.txt")); // "/tmp/ex1.txt" if (!file.open(QIODevice.OpenModeFlag.ReadWrite)) System.err.println("Cannot create the file " + file.fileName()); }A program that lists all the files in the current directory (excluding symbolic links), sorted by size, smallest first:
public static void main(String args[]) { QDir dir = new QDir(); dir.setFilter(new QDir.Filters(QDir.Filter.Files, QDir.Filter.Hidden, QDir.Filter.NoSymLinks)); dir.setSorting(new QDir.SortFlags(QDir.SortFlag.Size, QDir.SortFlag.Reversed)); List<QFileInfo> list = dir.entryInfoList(); for (QFileInfo fileInfo : list) { System.out.println(String.valueOf(fileInfo.size()) + " " + fileInfo.fileName() + "\n"); } }
QFileInfo
, QFile
, QFileDialog
, QApplication::applicationDirPath()
, and Find Files Example.
Nested Class Summary | |
---|---|
static class |
QDir.Filter
This class has no available documentation. |
static class |
QDir.Filters
This is a flags class for com.trolltech.qt.core.QDir.Filter |
static class |
QDir.SortFlag
This enum describes the sort options available to QDir , e.g. |
static class |
QDir.SortFlags
This is a flags class for com.trolltech.qt.core.QDir.SortFlag |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QDir()
Constructs a QDir pointing to the given directory path. |
|
QDir(QDir arg__1)
Constructs a QDir object that is a copy of the QDir object for directory dir. |
|
QDir(java.lang.String path)
Constructs a QDir pointing to the given directory path. |
|
QDir(java.lang.String path,
java.lang.String nameFilter)
Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters. |
|
QDir(java.lang.String path,
java.lang.String nameFilter,
QDir.SortFlags sort)
Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters. |
|
QDir(java.lang.String path,
java.lang.String nameFilter,
QDir.SortFlags sort,
QDir.Filter[] filter)
Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters. |
|
QDir(java.lang.String path,
java.lang.String nameFilter,
QDir.SortFlags sort,
QDir.Filters filter)
Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters. |
Method Summary | |
---|---|
java.lang.String |
absoluteFilePath(java.lang.String fileName)
Returns the absolute path name of a file in the directory. |
java.lang.String |
absolutePath()
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators. |
static void |
addSearchPath(java.lang.String prefix,
java.lang.String path)
Adds path to the search path for prefix. |
java.lang.String |
at(int i)
Returns the file name at position i in the list of file names. |
java.lang.String |
canonicalPath()
Returns the canonical path, i. |
boolean |
cd(java.lang.String dirName)
Changes the QDir 's directory to dirName. |
boolean |
cdUp()
Changes directory by moving one directory up from the QDir 's current directory. |
static java.lang.String |
cleanPath(java.lang.String path)
Removes all multiple directory separators "/" and resolves any ". |
QDir |
clone()
This method is reimplemented for internal reasons |
static java.lang.String |
convertSeparators(java.lang.String pathName)
Use QDir::toNativeSeparators() instead. |
int |
count()
Returns the total number of directories and files in the directory. |
static QDir |
current()
Returns the application's current directory. |
static java.lang.String |
currentPath()
Returns the absolute path of the application's current directory. |
java.lang.String |
dirName()
Returns the name of the directory; this is not the same as the path, e. |
static java.util.List |
drives()
Returns a list of the root directories on this system. |
java.util.List |
entryInfoList()
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). |
java.util.List |
entryInfoList(java.util.List nameFilters)
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). |
java.util.List |
entryInfoList(java.util.List nameFilters,
QDir.Filters filters)
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryInfoList(java.util.List nameFilters,
QDir.Filters filters,
QDir.SortFlag[] sort)
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryInfoList(java.util.List nameFilters,
QDir.Filters filters,
QDir.SortFlags sort)
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryInfoList(QDir.Filters filters)
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryInfoList(QDir.Filters filters,
QDir.SortFlag[] sort)
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryInfoList(QDir.Filters filters,
QDir.SortFlags sort)
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryList()
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). |
java.util.List |
entryList(java.util.List nameFilters)
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). |
java.util.List |
entryList(java.util.List nameFilters,
QDir.Filters filters)
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryList(java.util.List nameFilters,
QDir.Filters filters,
QDir.SortFlag[] sort)
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryList(java.util.List nameFilters,
QDir.Filters filters,
QDir.SortFlags sort)
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryList(QDir.Filters filters)
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryList(QDir.Filters filters,
QDir.SortFlag[] sort)
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
java.util.List |
entryList(QDir.Filters filters,
QDir.SortFlags sort)
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter() , and sorted according to the flags set with setSorting() . |
boolean |
exists()
Returns true if the directory exists; otherwise returns false. |
boolean |
exists(java.lang.String name)
Returns true if the file called name exists; otherwise returns false. |
java.lang.String |
filePath(java.lang.String fileName)
Returns the path name of a file in the directory. |
QDir.Filters |
filter()
Returns the value set by setFilter() |
static java.lang.String |
fromNativeSeparators(java.lang.String pathName)
Returns pathName using '/' as file separator. |
static QDir |
home()
Returns the user's home directory. |
static java.lang.String |
homePath()
Returns the absolute path of the user's home directory. |
boolean |
isAbsolute()
Returns true if the directory's path is absolute; otherwise returns false. |
static boolean |
isAbsolutePath(java.lang.String path)
Returns true if path is absolute; returns false if it is relative. |
boolean |
isReadable()
Returns true if the directory is readable and we can open files by name; otherwise returns false. |
boolean |
isRelative()
Returns true if the directory path is relative; otherwise returns false. |
static boolean |
isRelativePath(java.lang.String path)
Returns true if path is relative; returns false if it is absolute. |
boolean |
isRoot()
Returns true if the directory is the root directory; otherwise returns false. |
boolean |
makeAbsolute()
Converts the directory path to an absolute path. |
static boolean |
match(java.util.List filters,
java.lang.String fileName)
Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false. |
static boolean |
match(java.lang.String filter,
java.lang.String fileName)
Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false. |
boolean |
mkdir(java.lang.String dirName)
Creates a sub-directory called dirName. |
boolean |
mkpath(java.lang.String dirPath)
Creates the directory path dirPath. |
java.util.List |
nameFilters()
Returns the string list set by setNameFilters() |
java.lang.String |
path()
Returns the path. |
void |
refresh()
Refreshes the directory information. |
java.lang.String |
relativeFilePath(java.lang.String fileName)
Returns the path to fileName relative to the directory. |
boolean |
remove(java.lang.String fileName)
Removes the file, fileName. |
boolean |
rename(java.lang.String oldName,
java.lang.String newName)
Renames a file or directory from oldName to newName, and returns true if successful; otherwise returns false. |
boolean |
rmdir(java.lang.String dirName)
Removes the directory specified by dirName. |
boolean |
rmpath(java.lang.String dirPath)
Removes the directory path dirPath. |
static QDir |
root()
Returns the root directory. |
static java.lang.String |
rootPath()
Returns the absolute path of the root directory. |
static java.util.List |
searchPaths(java.lang.String prefix)
Returns the search paths for prefix. |
static char |
separator()
Returns the native directory separator. |
static boolean |
setCurrent(java.lang.String path)
Sets the application's current working directory to path. |
void |
setFilter(QDir.Filter[] filter)
Sets the filter used by entryList() and entryInfoList() to filters. |
void |
setFilter(QDir.Filters filter)
Sets the filter used by entryList() and entryInfoList() to filters. |
void |
setNameFilters(java.util.List nameFilters)
Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nameFilters. |
void |
setPath(java.lang.String path)
Sets the path of the directory to path. |
static void |
setSearchPaths(java.lang.String prefix,
java.util.List searchPaths)
Sets or replaces Qt's search paths for file names with the prefix prefix to searchPaths. |
void |
setSorting(QDir.SortFlag[] sort)
Sets the sort order used by entryList() and entryInfoList() . |
void |
setSorting(QDir.SortFlags sort)
Sets the sort order used by entryList() and entryInfoList() . |
QDir.SortFlags |
sorting()
Returns the value set by setSorting() |
static QDir |
temp()
Returns the system's temporary directory. |
static java.lang.String |
tempPath()
Returns the absolute path of the system's temporary directory. |
static java.lang.String |
toNativeSeparators(java.lang.String pathName)
Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. |
java.lang.String |
toString()
|
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 com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QDir(QDir arg__1)
QDir
object that is a copy of the QDir
object for directory dir.
public QDir()
QDir
pointing to the given directory path. If path is empty the program's working directory, ("."), is used. currentPath()
.
public QDir(java.lang.String path)
QDir
pointing to the given directory path. If path is empty the program's working directory, ("."), is used. currentPath()
.
public QDir(java.lang.String path, java.lang.String nameFilter, QDir.SortFlags sort, QDir.Filter[] filter)
QDir
with path path, that filters its entries by name using nameFilter and by attributes using filters. It also sorts the names using sort. The default nameFilter is an empty string, which excludes nothing; the default filters is AllEntries
, which also means exclude nothing. The default sort is Name
| IgnoreCase
, i.e. sort by name case-insensitively.
If path is an empty string, QDir
uses "." (the current directory). If nameFilter is an empty string, QDir
uses the name filter "*" (all files).
Note that path need not exist.
exists()
, setPath()
, setNameFilter(), setFilter()
, and setSorting()
.
public QDir(java.lang.String path, java.lang.String nameFilter, QDir.SortFlags sort)
QDir
with path path, that filters its entries by name using nameFilter and by attributes using filters. It also sorts the names using sort. The default nameFilter is an empty string, which excludes nothing; the default filters is AllEntries
, which also means exclude nothing. The default sort is Name
| IgnoreCase
, i.e. sort by name case-insensitively.
If path is an empty string, QDir
uses "." (the current directory). If nameFilter is an empty string, QDir
uses the name filter "*" (all files).
Note that path need not exist.
exists()
, setPath()
, setNameFilter(), setFilter()
, and setSorting()
.
public QDir(java.lang.String path, java.lang.String nameFilter)
QDir
with path path, that filters its entries by name using nameFilter and by attributes using filters. It also sorts the names using sort. The default nameFilter is an empty string, which excludes nothing; the default filters is AllEntries
, which also means exclude nothing. The default sort is Name
| IgnoreCase
, i.e. sort by name case-insensitively.
If path is an empty string, QDir
uses "." (the current directory). If nameFilter is an empty string, QDir
uses the name filter "*" (all files).
Note that path need not exist.
exists()
, setPath()
, setNameFilter(), setFilter()
, and setSorting()
.
public QDir(java.lang.String path, java.lang.String nameFilter, QDir.SortFlags sort, QDir.Filters filter)
QDir
with path path, that filters its entries by name using nameFilter and by attributes using filters. It also sorts the names using sort. The default nameFilter is an empty string, which excludes nothing; the default filters is AllEntries
, which also means exclude nothing. The default sort is Name
| IgnoreCase
, i.e. sort by name case-insensitively.
If path is an empty string, QDir
uses "." (the current directory). If nameFilter is an empty string, QDir
uses the name filter "*" (all files).
Note that path need not exist.
exists()
, setPath()
, setNameFilter(), setFilter()
, and setSorting()
.
Method Detail |
---|
public final java.lang.String absoluteFilePath(java.lang.String fileName)
exists()
. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()
). relativeFilePath()
, filePath()
, and canonicalPath()
.
public final java.lang.String absolutePath()
setPath()
, canonicalPath()
, exists()
, cleanPath()
, dirName()
, 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.
Example:
String bin = "/local/bin"; // where /local/bin is a symlink to /usr/bin QDir binDir = new QDir(bin); String canonicalBin = binDir.canonicalPath(); // canonicalBin now equals "/usr/bin" String ls = "/local/bin/ls"; // where ls is the executable "ls" QDir lsDir = new QDir(ls); String canonicalLs = lsDir.canonicalPath(); // canonicalLS now equals "/usr/bin/ls".
path()
, absolutePath()
, exists()
, cleanPath()
, dirName()
, and absoluteFilePath()
.
public final boolean cd(java.lang.String dirName)
QDir
's directory to dirName. Returns true if the new directory exists and is readable; otherwise returns false. Note that the logical cd()
operation is not performed if the new directory does not exist.
Calling cd("..") is equivalent to calling cdUp()
.
cdUp()
, isReadable()
, exists()
, and path()
.
public final boolean cdUp()
QDir
's current directory. Returns true if the new directory exists and is readable; otherwise returns false. Note that the logical cdUp()
operation is not performed if the new directory does not exist.
cd()
, isReadable()
, exists()
, and path()
.
public final int count()
Equivalent to entryList()
.count()
.
entryList()
.
public final java.lang.String dirName()
No check is made to ensure that a directory with this name actually exists; but see exists()
.
path()
, filePath()
, absolutePath()
, and absoluteFilePath()
.
public final java.util.List entryInfoList(QDir.Filters filters, QDir.SortFlag[] sort)
QFileInfo
objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The attribute filter and sorting specifications can be overridden using the filters and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryList()
, setNameFilters()
, setSorting()
, setFilter()
, isReadable()
, and exists()
.
public final java.util.List entryInfoList(QDir.Filters filters)
QFileInfo
objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The attribute filter and sorting specifications can be overridden using the filters and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryList()
, setNameFilters()
, setSorting()
, setFilter()
, isReadable()
, and exists()
.
public final java.util.List entryInfoList()
public final java.util.List entryInfoList(QDir.Filters filters, QDir.SortFlags sort)
QFileInfo
objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The attribute filter and sorting specifications can be overridden using the filters and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryList()
, setNameFilters()
, setSorting()
, setFilter()
, isReadable()
, and exists()
.
public final java.util.List entryInfoList(java.util.List nameFilters, QDir.Filters filters, QDir.SortFlag[] sort)
QFileInfo
objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryList()
, setNameFilters()
, setSorting()
, setFilter()
, isReadable()
, and exists()
.
public final java.util.List entryInfoList(java.util.List nameFilters, QDir.Filters filters)
QFileInfo
objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryList()
, setNameFilters()
, setSorting()
, setFilter()
, isReadable()
, and exists()
.
public final java.util.List entryInfoList(java.util.List nameFilters)
public final java.util.List entryInfoList(java.util.List nameFilters, QDir.Filters filters, QDir.SortFlags sort)
QFileInfo
objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryList()
, setNameFilters()
, setSorting()
, setFilter()
, isReadable()
, and exists()
.
public final java.util.List entryList(QDir.Filters filters, QDir.SortFlag[] sort)
setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The attribute filter and sorting specifications can be overridden using the filters and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryInfoList()
, setNameFilters()
, setSorting()
, and setFilter()
.
public final java.util.List entryList(QDir.Filters filters)
setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The attribute filter and sorting specifications can be overridden using the filters and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryInfoList()
, setNameFilters()
, setSorting()
, and setFilter()
.
public final java.util.List entryList()
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
public final java.util.List entryList(QDir.Filters filters, QDir.SortFlags sort)
setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The attribute filter and sorting specifications can be overridden using the filters and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryInfoList()
, setNameFilters()
, setSorting()
, and setFilter()
.
public final java.util.List entryList(java.util.List nameFilters, QDir.Filters filters, QDir.SortFlag[] sort)
setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryInfoList()
, setNameFilters()
, setSorting()
, and setFilter()
.
public final java.util.List entryList(java.util.List nameFilters, QDir.Filters filters)
setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryInfoList()
, setNameFilters()
, setSorting()
, and setFilter()
.
public final java.util.List entryList(java.util.List nameFilters)
The name filter attribute specification is overridden using the nameFilters argument.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
public final java.util.List entryList(java.util.List nameFilters, QDir.Filters filters, QDir.SortFlags sort)
setNameFilters()
and setFilter()
, and sorted according to the flags set with setSorting()
. The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.
Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.
entryInfoList()
, setNameFilters()
, setSorting()
, and setFilter()
.
public final boolean exists()
QFileInfo::exists()
, and QFile::exists()
.
public final boolean exists(java.lang.String name)
QFileInfo::exists()
, and QFile::exists()
.
public final java.lang.String filePath(java.lang.String fileName)
exists()
. If the QDir
is relative the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()
). dirName()
, absoluteFilePath()
, isRelative()
, and canonicalPath()
.
public final QDir.Filters filter()
setFilter()
setFilter()
.
public final boolean isAbsolute()
isAbsolutePath()
. isRelative()
, makeAbsolute()
, and cleanPath()
.
public final boolean isReadable()
Warning: A false value from this function is not a guarantee that files in the directory are not accessible.
QFileInfo::isReadable()
.
public final boolean isRelative()
makeAbsolute()
, isAbsolute()
, isAbsolutePath()
, and cleanPath()
.
public final boolean isRoot()
Note: If the directory is a symbolic link to the root directory this function returns false. If you want to test for this use canonicalPath()
, e.g.
QDir dir = new QDir("/tmp/root_link"); String dirPath = dir.canonicalPath(); if (new QDir(dirPath).isRoot()) System.err.println("It is a root link");
root()
, and rootPath()
.
public final boolean makeAbsolute()
isAbsolute()
, isAbsolutePath()
, isRelative()
, and cleanPath()
.
public final boolean mkdir(java.lang.String dirName)
Returns true on success; otherwise returns false.
rmdir()
.
public final boolean mkpath(java.lang.String dirPath)
The function will create all parent directories necessary to create the directory.
Returns true if successful; otherwise returns false.
rmpath()
.
public final java.util.List nameFilters()
setNameFilters()
setNameFilters()
.
public final java.lang.String path()
The returned path can be either absolute or relative (see setPath()
).
setPath()
, absolutePath()
, exists()
, cleanPath()
, dirName()
, absoluteFilePath()
, toNativeSeparators()
, and makeAbsolute()
.
public final void refresh()
public final java.lang.String relativeFilePath(java.lang.String fileName)
QDir dir = new QDir("/home/bob"); String s; s = dir.relativeFilePath("images/file.jpg"); // s is "images/file.jpg" s = dir.relativeFilePath("/home/mary/file.txt"); // s is "../mary/file.txt"
absoluteFilePath()
, filePath()
, and canonicalPath()
.
public final boolean remove(java.lang.String fileName)
Returns true if the file is removed successfully; otherwise returns false.
public final boolean rename(java.lang.String oldName, java.lang.String newName)
On most file systems, rename()
fails only if oldName does not exist, if newName and oldName are not on the same partition or if a file with the new name already exists. However, there are also other reasons why rename()
can fail. For example, on at least one file system rename()
fails if newName points to an open file.
public final boolean rmdir(java.lang.String dirName)
The directory must be empty for rmdir()
to succeed.
Returns true if successful; otherwise returns false.
mkdir()
.
public final boolean rmpath(java.lang.String dirPath)
The function will remove all parent directories in dirPath, provided that they are empty. This is the opposite of mkpath(dirPath).
Returns true if successful; otherwise returns false.
mkpath()
.
public final void setFilter(QDir.Filter[] filter)
entryList()
and entryInfoList()
to filters. The filter is used to specify the kind of files that should be returned by entryList()
and entryInfoList()
. See QDir::Filter
. filter()
, and setNameFilters()
.
public final void setFilter(QDir.Filters filter)
entryList()
and entryInfoList()
to filters. The filter is used to specify the kind of files that should be returned by entryList()
and entryInfoList()
. See QDir::Filter
. filter()
, and setNameFilters()
.
public final void setNameFilters(java.util.List nameFilters)
entryList()
and entryInfoList()
to the list of filters specified by nameFilters. Each name filter is a wildcard (globbing) filter that understands * and ? wildcards. (See QRegExp wildcard matching
.)
For example, the following code sets three name filters on a QDir
to ensure that only files with extensions typically used for C++ source files are listed:
List<String> filters = new Vector<String>(); filters.add("*.cpp"); filters.add("*.cxx"); filters.add("*.cc"); dir.setNameFilters(filters);
nameFilters()
, and setFilter()
.
public final void setPath(java.lang.String path)
exists()
. The path can be either absolute or relative. Absolute paths begin with the directory separator "/" (optionally preceded by 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. An example of an absolute path is the string "/tmp/quartz", a relative path might look like "src/fatlib".
path()
, absolutePath()
, exists()
, cleanPath()
, dirName()
, absoluteFilePath()
, isRelative()
, and makeAbsolute()
.
public final void setSorting(QDir.SortFlag[] sort)
entryList()
and entryInfoList()
. The sort is specified by OR-ing values from the enum QDir::SortFlag
.
sorting()
, and SortFlag
.
public final void setSorting(QDir.SortFlags sort)
entryList()
and entryInfoList()
. The sort is specified by OR-ing values from the enum QDir::SortFlag
.
sorting()
, and SortFlag
.
public final QDir.SortFlags sorting()
setSorting()
setSorting()
, and SortFlag
.
public static void addSearchPath(java.lang.String prefix, java.lang.String path)
setSearchPaths()
.
public static java.lang.String cleanPath(java.lang.String path)
Symbolic links are kept. This function does not return the canonical path, but rather the simplest version of the input. For example, "./local" becomes "local", "local/../bin" becomes "bin" and "/local/usr/../bin" becomes "/local/bin".
absolutePath()
, and canonicalPath()
.
public static java.lang.String convertSeparators(java.lang.String pathName)
QDir::toNativeSeparators()
instead.
public static QDir current()
The directory is constructed using the absolute path of the current directory, ensuring that its path()
will be the same as its absolutePath()
.
setCurrent()
, currentPath()
, home()
, root()
, and temp()
.
public static java.lang.String currentPath()
current()
, homePath()
, rootPath()
, and tempPath()
.
public static java.util.List drives()
On Windows this returns a list of QFileInfo
objects containing "C:/", "D:/", etc. On other operating systems, it returns a list containing just one root directory (i.e. "/").
root()
, and rootPath()
.
public static java.lang.String fromNativeSeparators(java.lang.String pathName)
The returned string may be the same as the argument on some operating systems, for example on Unix.
toNativeSeparators()
, and separator()
.
public static QDir home()
The directory is constructed using the absolute path of the home directory, ensuring that its path()
will be the same as its absolutePath()
.
See homePath()
for details.
drives()
, current()
, root()
, and temp()
.
public static java.lang.String homePath()
Under Windows this function will return the directory of the current user's profile. Typically, this is:
C:/Documents and Settings/UsernameUse the
toNativeSeparators()
function to convert the separators to the ones that are appropriate for the underlying operating system. If the directory of the current user's profile does not exist or cannot be retrieved, the following alternatives will be checked (in the given order) until an existing and available path is found:
rootPath()
function (which uses the SystemDrive environment variable)rootPath()
function is used. home()
, currentPath()
, rootPath()
, and tempPath()
.
public static boolean isAbsolutePath(java.lang.String path)
isAbsolute()
, isRelativePath()
, makeAbsolute()
, and cleanPath()
.
public static boolean isRelativePath(java.lang.String path)
isRelative()
, isAbsolutePath()
, and makeAbsolute()
.
public static boolean match(java.lang.String filter, java.lang.String fileName)
QRegExp wildcard matching
, QRegExp::exactMatch()
, entryList()
, and entryInfoList()
.
public static boolean match(java.util.List filters, java.lang.String fileName)
QRegExp wildcard matching
, QRegExp::exactMatch()
, entryList()
, and entryInfoList()
.
public static QDir root()
The directory is constructed using the absolute path of the root directory, ensuring that its path()
will be the same as its absolutePath()
.
See rootPath()
for details.
drives()
, current()
, home()
, and temp()
.
public static java.lang.String rootPath()
For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/".
root()
, drives()
, currentPath()
, homePath()
, and tempPath()
.
public static java.util.List searchPaths(java.lang.String prefix)
setSearchPaths()
, and addSearchPath()
.
public static char separator()
You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators()
.
public static boolean setCurrent(java.lang.String path)
current()
, currentPath()
, home()
, root()
, and temp()
.
public static void setSearchPaths(java.lang.String prefix, java.util.List searchPaths)
To specify a prefix for a file name, prepend the prefix followed by a single colon (e.g., "images:undo.png", "xmldocs:books.xml"). prefix can only contain letters or numbers (e.g., it cannot contain a colon, nor a slash).
Qt uses this search path to locate files with a known prefix. The search path entries are tested in order, starting with the first entry.
List<String> imagesSearchPaths = new Vector<String>(); imagesSearchPaths.add(QDir.homePath() + "/images"); List<String> docSearchPaths = new Vector<String>(); docSearchPaths.add(":/embeddedDocuments"); QDir.setSearchPaths("icons", imagesSearchPaths); QDir.setSearchPaths("docs", docSearchPaths); //... QPixmap pixmap = new QPixmap("icons:undo.png"); // will look for undo.png in QDir.homePath() + "/images" QFile file = new QFile("docs:design.odf"); // will look in the :/embeddedDocuments resource pathFile name prefix must be at least 2 characters long to avoid conflicts with Windows drive letters.
Search paths may contain paths to The Qt Resource System.
searchPaths()
.
public static QDir temp()
The directory is constructed using the absolute path of the temporary directory, ensuring that its path()
will be the same as its absolutePath()
.
See tempPath()
for details.
drives()
, current()
, home()
, and root()
.
public static java.lang.String tempPath()
On Unix/Linux systems this is usually /tmp; on Windows this is usually the path in the TEMP or TMP environment variable. Whether a directory separator is added to the end or not, depends on the operating system.
temp()
, currentPath()
, homePath()
, and rootPath()
.
public static java.lang.String toNativeSeparators(java.lang.String pathName)
On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\winnt\system32".
The returned string may be the same as the argument on some operating systems, for example on Unix.
fromNativeSeparators()
, and separator()
.
public java.lang.String at(int i)
public java.lang.String toString()
toString
in class java.lang.Object
public QDir clone()
clone
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |