Qt Components Hildon  0.20
QML components for Maemo5 with Hildon styling.
 All Classes Functions Properties Groups Pages
Public Member Functions | Properties | List of all members
Directory Class Reference

Provides access to directory structures and their contents. More...

Public Member Functions

string absoluteFilePath (string fileName) const
 Returns the absolute path name of a file in the directory.
void addSearchPath (string prefix, string path)
 Adds path to the search path for prefix.
bool cd (string dirName)
 Changes the Directory's directory to dirName.
bool cdUp ()
 Changes directory by moving one directory up from the Directory's current directory.
string cleanPath (string path)
 Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path, path.
list< string > entryList () const
 Returns a list of the names of all the files and directories in the directory, ordered according to filter and nameFilters, and sorted according to sorting.
bool fileExists (string fileName) const
 Returns true if the file called fileName exists; otherwise returns false.
string filePath (string fileName) const
 Returns the path name of a file in the directory.
bool makeAbsolute ()
 Converts the directory path to an absolute path.
bool match (string filter, string fileName)
 Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false.
bool match (list< string > filters, string fileName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false.
bool mkdir (string dirName) const
 Creates a sub-directory called dirName.
bool mkpath (string dirPath) const
 Creates the directory path dirPath.
list< string > nameFilters () const
 The name filters used by entryList().
void refresh ()
 Refreshes the directory information.
string relativeFilePath (string fileName) const
 Returns the path to fileName relative to the directory.
bool remove (string fileName)
 Removes the file, fileName.
bool rename (string oldName, string newName)
 Renames a file or directory from oldName to newName, and returns true if successful; otherwise returns false.
bool rmdir (string dirName) const
 Removes the directory specified by dirName.
bool rmpath (string dirPath) const
 Removes the directory path dirPath.
list< string > searchPaths (string prefix)
 Returns the search paths for prefix.
void setSearchPaths (string prefix, list< string > searchPaths)
 Sets or replaces Qt's search paths for file names with the prefix prefix to searchPaths.

Properties

bool absolute
 Whether the directory's path is absolute.
string absolutePath
 The absolute path of the directory.
string canonicalPath
 The canonical path of the directory.
int count
 The number of results in the directory.
string currentPath
 The current path of the directory.
string dirName
 The name of the directory.
bool exists
 Whether the directory exists.
flags filter
 The filter used by entryList().
string homePath
 The home path of the system.
string path
 The path of the directory.
bool readable
 Whether the directory is readable.
bool root
 Whether the directory's path is the root path.
string rootPath
 The root path of the system.
flags sorting
 The sorting used by entryList().
string tempPath
 The temp path of the system.

Detailed Description

Provides access to directory structures and their contents.

A Directory 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.

A Directory can point to a file using either a relative or an absolute path. Absolute paths begin with the directory separator.

Relative file names begin with a directory name or a file name and specify a path relative to the current directory.

import QtQuick 1.0
import org.hildon.components 1.0
import org.hildon.utils 1.0
Window {
id: window
title: qsTr("Directory Example")
visible: true
Column {
id: column
anchors {
left: parent.left
right: parent.right
top: parent.top
}
width: parent.width
text: qsTr("Directory")
}
id: dirField
width: parent.width
text: "/home/user/MyDocs/"
}
Button {
id: button
width: parent.width
text: qsTr("List files")
onClicked: edit.text = dir.entryList().join("\n")
}
width: parent.width
text: qsTr("Results")
}
id: edit
width: parent.width
readOnly: true
}
}
id: dir
path: dirField.text ? dirField.text : "/home/user/MyDocs/"
}
}
Examples:
directory.qml.

Member Function Documentation

string Directory::absoluteFilePath ( string  fileName) const

Returns the absolute path name of a file in the directory.

Does not check if the file actually exists in the directory. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()).

See Also
relativeFilePath(), filePath(), canonicalPath()
void Directory::addSearchPath ( string  prefix,
string  path 
)

Adds path to the search path for prefix.

See Also
setSearchPaths()
bool Directory::cd ( string  dirName)

Changes the Directory'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().

See Also
cdUp(), readable, exists, path
bool Directory::cdUp ( )

Changes directory by moving one directory up from the Directory'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.

See Also
cd(), readable, exists, path
string Directory::cleanPath ( string  path)

Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path, 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".

See Also
absolutePath(), canonicalPath()
list< string > Directory::entryList ( ) const

Returns a list of the names of all the files and directories in the directory, ordered according to filter and nameFilters, and sorted according to sorting.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

See Also
nameFilters, sorting, filter
bool Directory::fileExists ( string  fileName) const

Returns true if the file called fileName exists; otherwise returns false.

Unless fileName contains an absolute file path, the file name is assumed to be relative to the directory itself, so this function is typically used to check for the presence of files within a directory.

string Directory::filePath ( string  fileName) const

Returns the path name of a file in the directory.

Does not check if the file actually exists in the directory. If the Directory is relative the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()).

See Also
dirName, absoluteFilePath(), relative, canonicalPath()
bool Directory::makeAbsolute ( )

Converts the directory path to an absolute path.

If it is already absolute nothing happens. Returns true if the conversion succeeded; otherwise returns false.

See Also
absolute, relative, cleanPath()
bool Directory::match ( string  filter,
string  fileName 
)

Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false.

The filter may contain multiple patterns separated by spaces or semicolons. The matching is case insensitive.

See Also
entryList()
bool Directory::match ( list< string >  filters,
string  fileName 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false.

The matching is case insensitive.

See Also
entryList()
bool Directory::mkdir ( string  dirName) const

Creates a sub-directory called dirName.

Returns true on success; otherwise returns false.

If the directory already exists when this function is called, it will return false.

See Also
rmdir()
bool Directory::mkpath ( string  dirPath) const

Creates the directory path dirPath.

The function will create all parent directories necessary to create the directory.

Returns true if successful; otherwise returns false.

If the path already exists when this function is called, it will return true.

See Also
rmpath()
list< string > Directory::nameFilters ( ) const

The name filters used by entryList().

The name filters are a list of wildcards, e.g:

/code nameFilters: [ "*.jpg", "*.jpeg", "*.png", "*.svg" ] /endcode

string Directory::relativeFilePath ( string  fileName) const

Returns the path to fileName relative to the directory.

See Also
absoluteFilePath(), filePath(), canonicalPath()
bool Directory::remove ( string  fileName)

Removes the file, fileName.

Returns true if the file is removed successfully; otherwise returns false.

bool Directory::rename ( string  oldName,
string  newName 
)

Renames a file or directory from oldName to newName, and returns true if successful; otherwise returns false.

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.

bool Directory::rmdir ( string  dirName) const

Removes the directory specified by dirName.

The directory must be empty for rmdir() to succeed.

Returns true if successful; otherwise returns false.

See Also
mkdir()
bool Directory::rmpath ( string  dirPath) const

Removes the directory path 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.

See Also
mkpath()
list< string > Directory::searchPaths ( string  prefix)

Returns the search paths for prefix.

See Also
setSearchPaths(), addSearchPath()
void Directory::setSearchPaths ( string  prefix,
list< string >  searchPaths 
)

Sets or replaces Qt's search paths for file names with the prefix prefix to 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.

Search paths may contain paths to Qt Resource System.

Property Documentation

flags Directory::filter
readwrite

The filter used by entryList().

The value of this property is a bitwise OR combination of the following:

Value Description
Directory.Dirs List directories that match the filters.
Directory.AllDirs List all directories; i.e. don't apply the filters to directory names.
Directory.Files List files.
Directory.NoSymLinks Do not list symbolic links.
Directory.NoDotAndDotDot Do not list the special entries "." and "..".
Directory.NoDot Do not list the special entry ".".
Directory.NoDotDot Do not list the special entry "..".
Directory.AllEntries List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System).
Directory.Readable List files for which the application has read access.
Directory.Writable List files for which the application has write access.
Directory.Executable List files for which the application has execute access.
Directory.Hidden List hidden files.
Directory.System List system files.
Directory.CaseSensitive The filter should be case sensitive.
flags Directory::sorting
readwrite

The sorting used by entryList().

The value of this property is a bitwise OR combination of the following:

Value Description
Directory.Name Sort by name.
Directory.Time Sort by modification time.
Directory.Size Sort by file size.
Directory.Type Sort by file extension.
Directory.NoDotAndDotDot Do not list the special entries "." and "..".
Directory.Unsorted Do not sort.
Directory.NoSort Not sorted by default.
Directory.DirsFirst Put directories first, then the files.
Directory.DirsLast Put files first, then the directories.
Directory.Reversed Reverse the sort order.
Directory.IgnoreCase Sort case-insensitively.
Directory.LocalAware Sort items appropriately using the current locale settings.