UaDir Class Reference

The UaDir class provides access to directory structures and their contents. A UaDir is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system. Ua 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, Ua will translate your paths to conform to the underlying operating system. A UaDir 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:. More...

#include <uadir.h>

Collaboration diagram for UaDir:

List of all members.


Public Types

enum  Filters {
  NoFilter = 0, Dirs = 1, Files = 2, Drives = 4,
  NoSymLinks = 8, NoDotAndDotDot = 16, Readable = 32, Writeable = 64,
  Executable = 128
}
enum  SortFlags { NoSort = 0, Name = 1, Time = 2, Size = 4 }

Public Member Functions

 UaDir (const UaUniString &sPath)
 ~UaDir ()
UaUniString getPath () const
UaUniString canonicalPath () const
UaUniString filePath (const UaUniString &sFileName) const
UaUniStringList entryList (const UaUniString &sPath, int filters=UaDir::NoFilter, int sort=UaDir::NoSort) const
bool cd (const UaUniString &sDirName)
bool copy (const UaUniString &fileName, const UaUniString &newName)
bool createFile (const UaUniString &sPath, const UaUniString &sFileName)
bool isRelativePath (const UaUniString &sPath) const
bool link (const UaUniString &fileName, const UaUniString &newName)
bool mkpath (const UaUniString &sDirName) const
bool remove (const UaUniString &sFileName)
bool rename (const UaUniString &sOldName, const UaUniString &sNewName)
bool rmpath (const UaUniString &sDirPath) const
bool exists (const UaUniString &sPath) const
OpcUa_UInt16 count (const UaUniString &sPath) const

Static Public Member Functions

static UaUniString applicationDataPath ()
static UaUniString homePath ()
static UaUniString systemApplicationDataPath ()
static UaUniString fromNativeSeparators (const UaUniString &sPathName)
static UaUniString toNativeSeparators (const UaUniString &sPathName)
static UaChar separator ()

Detailed Description

The UaDir class provides access to directory structures and their contents. A UaDir is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system. Ua 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, Ua will translate your paths to conform to the underlying operating system. A UaDir 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:.

UaDir

      UaDir("/home/user/Documents")
      UaDir("C:/Documents and Settings")
On Windows, the second of the examples above will be translated to {C:\My Documents} when used to access files. Examples of relative paths:
      UaDir("images/landscape.png")

Member Enumeration Documentation

This enum describes the filtering options available to UaDir; e.g. for entryList(). The filter value is specified by combining values from the following list using the bitwise OR operator:

Enumerator:
NoFilter  no filter
Dirs  List directories that match the filters.
Files  List files only.
Drives  List disk drives (ignored under Unix).
NoSymLinks  Do not list symbolic links (ignored by operating systems that don't support symbolic links).
NoDotAndDotDot  Do not list the special entries "." and "..".
Readable  List files for which the application has read access. The Readable value needs to be combined with Dirs or Files.
Writeable  List files for which the application has write access. The Writable value needs to be combined with Dirs or Files.
Executable  List files for which the application has execute access. The Executable value needs to be combined with Dirs or Files.

This enum describes the sort options available to UaDir, e.g. for entryList(). The sort value is specified by OR-ing together values from the following list:

Enumerator:
NoSort  Do not sort.
Name  Sort by name.
Time  Sort by time (modification time).
Size  Sort by file size.


Constructor & Destructor Documentation

UaDir::UaDir ( const UaUniString sPath  ) 

construction

Parameters:
sPath a path to a file.

UaDir::~UaDir (  ) 

destruction


Member Function Documentation

UaUniString UaDir::getPath (  )  const [inline]

Get the path.

Returns:
the path.

UaUniString UaDir::canonicalPath (  )  const

Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements. 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:

      UaUniString bin = "/local/bin";         // where /local/bin is a symlink to /usr/bin
      UaDir binDir(bin);
      UaUniString canonicalBin = binDir.canonicalPath();
      // canonicalBin now equals "/usr/bin"

      UaUniString ls = "/local/bin/ls";       // where ls is the executable "ls"
      UaDir lsDir(ls);
      UaUniString canonicalLs = lsDir.canonicalPath();
      // canonicalLS now equals "/usr/bin/ls".

UaUniString UaDir::filePath ( const UaUniString sFileName  )  const

Returns the path name of a file in the directory. Does not check if the file actually exists in the directory. If the UaDir is relative the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in fileName are not removed.

See also:
canonicalPath()

UaUniStringList UaDir::entryList ( const UaUniString sPath,
int  filters = UaDir::NoFilter,
int  sort = UaDir::NoSort 
) const

Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters. 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.

bool UaDir::cd ( const UaUniString sDirName  ) 

Changes the UaDir's directory to sDirName. 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.

bool UaDir::copy ( const UaUniString fileName,
const UaUniString newName 
)

The copy function copies an existing file to an new file.

Parameters:
fileName the original file name to copy.
newName the new name of the copied file.
Returns:
true if successfull false if not.

bool UaDir::createFile ( const UaUniString sPath,
const UaUniString sFileName 
)

Create a new file and opens it for writing.

Parameters:
sPath path to the new file.
sFileName the name of the new file.
Returns:
true if successfull false if not.

bool UaDir::isRelativePath ( const UaUniString sPath  )  const

Returns true if sPath is relative; returns false if it is absolute. (Under Unix a path is relative if it does not start with a "/").

bool UaDir::link ( const UaUniString fileName,
const UaUniString newName 
)

Create a hard link to a new file. Establishes a hard link between an existing file and a new file.

Parameters:
fileName path to the file to link with.
newName the new name of the linked file.
Returns:
true if successfull false if not.

bool UaDir::mkpath ( const UaUniString sDirName  )  const

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

Returns:
true if successful; otherwise returns false.
See also:
rmpath()

bool UaDir::remove ( const UaUniString sFileName  ) 

Removes the file, sFileName.

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

bool UaDir::rename ( const UaUniString sOldName,
const UaUniString sNewName 
)

Renames a file or directory from sOldName to sNewName, and returns true if successful; otherwise returns false. On most file systems, rename() fails only if sOldName does not exist, if sNewName and sOldName 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 sNewName points to an open file.

bool UaDir::rmpath ( const UaUniString sDirPath  )  const

Removes the directory path sDirPath. The function will remove all parent directories in sDirPath, provided that they are empty. This is the opposite of mkpath(sDirName).

Returns:
true if successful; otherwise returns false.

bool UaDir::exists ( const UaUniString sPath  )  const

Checks if the given path still exists or not.

Parameters:
sPath the path to the file / directory.
Returns:
true if the path exists, false if not.

OpcUa_UInt16 UaDir::count ( const UaUniString sPath  )  const

Returns the total number of directories and files in the directory (including "." and "..")

Parameters:
sPath the path to the directory where to count all the files and dirs.
Returns:
the total number of directories and files. -1 if an error occured.

UaUniString UaDir::applicationDataPath (  )  [static]

Get the path to the application folder (<username> Data).

Returns:
the path to the application folder (<username> Data).

UaUniString UaDir::homePath (  )  [static]

Returns the absolute path of the user's home directory. Under Windows this function will return the directory of the current user's profile. Typically, this is:

      C:/Documents and Settings/Username

UaUniString UaDir::systemApplicationDataPath (  )  [static]

Get the path to the application folder (All Users Data).

Returns:
the path to the application folder (All Users Data).

UaUniString UaDir::fromNativeSeparators ( const UaUniString sPathName  )  [static]

Returns pathName using '/' as file separator. On Windows, for instance, fromNativeSeparators("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.

See also:
toNativeSeparators()

UaUniString UaDir::toNativeSeparators ( const UaUniString sPathName  )  [static]

Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. 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.

UaChar UaDir::separator (  )  [static]

Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows. You do not need to use this function to build file paths. If you always use "/", Ua 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().


The documentation for this class was generated from the following files:
  • src/uabase/uabasecpp/uadir.h
  • src/uabase/uabasecpp/uadir.cpp