v1.2.0.1-beta1

Description

The Dir class provides static functions for directory operations, which are accessed in JS with the Dir. qualifier. These are "atomic" operations such as getting information about a path, manipulating directories and so forth.

Public Member Functions

bool mkpath (String &path)
 
bool mkdir (String &dirName)
 
bool rmpath (String &path)
 
bool rmdir (String &dirName, bool recurse=false)
 
bool exists (String &path)
 
bool isAbs (String &path)
 
String cwd ()
 
String home ()
 
String temp ()
 
String root ()
 
String separator ()
 
String toNative (String &path)
 
String fromNative (String &path)
 
String clean (String &path)
 
String abs (String &path)
 
String normalize (String &path)
 

Member Function Documentation

◆ mkpath()

bool mkpath ( String path)

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

◆ mkdir()

bool mkdir ( String dirName)

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.

◆ rmpath()

bool rmpath ( String path)

Removes the directory path path. The function will remove all parent directories in path, provided that they are empty. This is the opposite of mkpath(). Returns true if successful; otherwise returns false.

◆ rmdir()

bool rmdir ( String dirName,
bool  recurse = false 
)

This function has two modes of operation:

  • If recurse = false (default): Removes the directory specified by dirName. The directory must be empty for rmdir() to succeed.
  • If recurse = true: Removes the directory specified by dirName, including all its contents. If a file or directory cannot be removed it keeps going and attempts to delete as many files and sub-directories as possible, then returns false. If the directory was already removed, the method returns true (expected result already reached). Returns true if successful; otherwise returns false, except as noted above.

◆ exists()

bool exists ( String path)

Returns true if path exists in the file system, false otherwise.

◆ isAbs()

bool isAbs ( String path)

Returns true if path is absolute (that is, from a root directory), false otherwise (if it relative).

◆ cwd()

String cwd ( )

Returns the absolute path of the application's current directory. The current directory is the directory at which this application was started at by the parent process.

◆ home()

String home ( )

Returns the absolute path of the user's home directory. (Under Windows this function will return the directory of the current user's profile, eg C:/Users/Username) Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath().

◆ temp()

String temp ( )

Returns the absolute canonical path of the system's temporary directory. On Unix/Linux systems this is the path in the TMPDIR environment variable or /tmp if TMPDIR is not defined. On Windows this is usually the path in the TEMP or TMP environment variable. The path returned by this method doesn't end with a directory separator unless it is the root directory (of a drive).

◆ root()

String root ( )

Returns the absolute path of the root directory. For Windows file systems this normally returns the boot drive letter (typically "c:/"). For Unix/Mac operating systems this returns "/".

◆ separator()

String separator ( )

Returns the native directory separator: "/" under Unix and "\" under Windows. Note: You do not need to use this function to build file paths. You can always use "/" and it will be adjusted if needed.

◆ toNative()

String toNative ( String path)

Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.

◆ fromNative()

String fromNative ( String path)

Returns pathName using '/' as file separator.

◆ clean()

String clean ( String path)

Returns path with directory separators normalized (that is, platform-native separators converted to "/") and redundant ones removed, and "."s and ".."s resolved (as far as possible). Symbolic links are kept.

◆ abs()

String abs ( String path)

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.

◆ normalize()

String normalize ( String path)

Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements.