v1.3.0.0

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)
 
FileInfo info (string &path)
 
string cwd ()
 
string home ()
 
string root ()
 
string temp ()
 
string abs (string &path)
 
string clean (string &path)
 
string fromNative (string &path)
 
string normalize (string &path)
 
string separator ()
 
string toNative (string &path)
 
Array< string > list (string &path, Array< string > &nameFilters=Array< string >(), FS::DirFilters filters=FS::NoFilter, FS::DirSortFlags sort=FS::SortDefault, int maxResults=0)
 
Array< string > list (string &path, FS::DirFilters filters, FS::DirSortFlags sort=FS::SortDefault, int maxResults=0)
 
Array< string > list (string &path, FS::DirSortFlags sort, int maxResults=0)
 
Array< FileInfoinfoList (string &path, Array< string > &nameFilters=Array< string >(), FS::DirFilters filters=FS::NoFilter, FS::DirSortFlags sort=FS::SortDefault, int maxResults=0)
 
Array< FileInfoinfoList (string &path, FS::DirFilters filters, FS::DirSortFlags sort=FS::SortDefault, int maxResults=0)
 
Array< FileInfoinfoList (string &path, FS::DirSortFlags sort, int maxResults=0)
 

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).

◆ info()

FileInfo info ( string &  path)

Returns a FileInfo object describing the file or directory at the given path. Relative paths are resolved against the current working directory (Dir.cwd()). This function is equivalent to File.info().

Since
1.2.1

◆ 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().

◆ 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 "/".

◆ 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).

◆ 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.

◆ 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 Note that unlike normalize(), the existence of the path target is not verified. This method always returns non-empty string, assuming path argument wasn't empty in the first place.

See also
normalize()

◆ fromNative()

string fromNative ( string &  path)

Returns pathName using '/' as file separator.

See also
toNative()

◆ normalize()

string normalize ( string &  path)

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

Note
The target of the normalized path must exist, otherwise this method returns an empty string. To simplify a path w/out validating or resolving links, use clean().
See also
clean()

◆ 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.

See also
fromNative(), separator()

◆ list() [1/3]

Array< string > list ( string &  path,
Array< string > &  nameFilters = Array<string>(),
FS::DirFilters  filters = FS::NoFilter,
FS::DirSortFlags  sort = FS::SortDefault,
int  maxResults = 0 
)

Returns an array of directory entry names in the given path.

Parameters
pathThe directory to list. Relative paths are resolved against the current working directory (Dir.cwd()).
nameFiltersA list of file glob patterns to include, or an empty list for no filter. For example ["*.png,", "*.jpg", "*.gif"]
filtersA combination of FS::DirFilters filter flags to apply to the results.
sortA combination of FS::DirSortFlags flags to use for sorting the results.
maxResultsMaximum number of results to return; Set to 0 (default) to return all results.
See also
Dir.infoList()
Since
1.2.1

◆ list() [2/3]

Array< string > list ( string &  path,
FS::DirFilters  filters,
FS::DirSortFlags  sort = FS::SortDefault,
int  maxResults = 0 
)

Returns an array of directory entry names in the given path. This is an overloaded function.

Parameters
pathThe directory to list. Relative paths are resolved against the current working directory (Dir.cwd()).
filtersA combination of FS::DirFilters filter flags to apply to the results.
sortA combination of FS::DirSortFlags flags to use for sorting the results.
maxResultsMaximum number of results to return; Set to 0 (default) to return all results.
See also
Dir.infoList()
Since
1.2.1

◆ list() [3/3]

Array< string > list ( string &  path,
FS::DirSortFlags  sort,
int  maxResults = 0 
)

Returns an array of directory entry names in the given path. This is an overloaded function.

Parameters
pathThe directory to list. Relative paths are resolved against the current working directory (Dir.cwd()).
sortA combination of FS::DirSortFlags flags to use for sorting the results.
maxResultsMaximum number of results to return; Set to 0 (default) to return all results.
See also
Dir.infoList()
Since
1.2.1

◆ infoList() [1/3]

Array< FileInfo > infoList ( string &  path,
Array< string > &  nameFilters = Array<string>(),
FS::DirFilters  filters = FS::NoFilter,
FS::DirSortFlags  sort = FS::SortDefault,
int  maxResults = 0 
)

Returns an array of directory entries in the given path as FileInfo objects.

Parameters
pathThe directory to list. Relative paths are resolved against the current working directory (Dir.cwd()).
nameFiltersA list of file glob patterns to include, or an empty list for no filter. For example ["*.png,", "*.jpg", "*.gif"]
filtersA combination of FS::DirFilters filter flags to apply to the results.
sortA combination of FS::DirSortFlags flags to use for sorting the results.
maxResultsMaximum number of results to return; Set to 0 (default) to return all results.
See also
Dir.list()
Since
1.2.1

◆ infoList() [2/3]

Array< FileInfo > infoList ( string &  path,
FS::DirFilters  filters,
FS::DirSortFlags  sort = FS::SortDefault,
int  maxResults = 0 
)

Returns an array of directory entries in the given path as FileInfo objects. This is an overloaded function.

Parameters
pathThe directory to list. Relative paths are resolved against the current working directory (Dir.cwd()).
filtersA combination of FS::DirFilters filter flags to apply to the results.
sortA combination of FS::DirSortFlags flags to use for sorting the results.
maxResultsMaximum number of results to return; Set to 0 (default) to return all results.
See also
Dir.list()
Since
1.2.1

◆ infoList() [3/3]

Array< FileInfo > infoList ( string &  path,
FS::DirSortFlags  sort,
int  maxResults = 0 
)

Returns an array of directory entries in the given path as FileInfo objects. This is an overloaded function.

Parameters
pathThe directory to list. Relative paths are resolved against the current working directory (Dir.cwd()).
sortA combination of FS::DirSortFlags flags to use for sorting the results.
maxResultsMaximum number of results to return; Set to 0 (default) to return all results.
See also
Dir.list()
Since
1.2.1