ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
Directory Class Reference

Description:


Represents a directory (folder) in a file system.

Note
This class is not recommended to be used. It was created once to have something for class IniFile , but never came to a state of true usability.

Definition at line 42 of file directory.hpp.

#include <directory.hpp>

Collaboration diagram for Directory:
[legend]

Public Type Index:

enum class  SpecialFolder {
  Root , Current , Home , HomeConfig ,
  Module , Temp , VarTemp
}
 

Public Static Field Index:

static AString evaluatedTempDir
 
static AString evaluatedVarTempDir
 

Public Static Method Index:

static ALIB_API SystemErrors Create (const CString &path)
 
static ALIB_API bool CurrentDirectory (AString &target)
 
static ALIB_API bool Exists (const CString &path)
 
static bool Exists (const StringNZT &path)
 

Public Field Index:

AString Path
 

Public Method Index:

 Directory ()
 
 Directory (const String &path)
 
 Directory (SpecialFolder special)
 
ALIB_API bool Change (const CString &path)
 
ALIB_API bool Change (const StringNZT &path)
 
ALIB_API void Change (SpecialFolder special)
 

Enumeration Details:

◆ SpecialFolder

enum class SpecialFolder
strong

Denotes upper and lower case character conversions

Enumerator
Root 

The root directory .

Current 

The current directory of the process.

Home 

The user's home directory

HomeConfig 

The user's configuration directory. This is evaluated as follows:

  • Using environment variable HOME (under WindowsOS a combination of HOMEDRIVE and HOMEPATH), the home directory is determined.
  • If within this a directory ".config" exists, it is used, otherwise
  • if within this the directories "AppData/Roaming" exist, this is used.
Module 

The directory of the executable of the process.

Temp 

A directory to be used for creation of temporary files.

  • On GNU/Linux OS this defaults to /tmp.
  • On Windows OS, environment variables TMP and TEMP are evaluated.

If the directory does not exist, then (on all OS), a new directory named ".tmp" is created in the user's home directory and returned (if not existent already). If this fails, the home directory itself is returned.

Note
With the potential creation of the directory ".tmp" in the user's home directory, a small readme.txt file is created containing the name of the running application and the reason of the creation.

To overrule this behavior, public static variable evaluatedTempDir may be set arbitrarily prior to using this enum value.

VarTemp 

A directory to be used for creation of temporary files that survives reboots of the host machine.

  • On GNU/Linux OS this defaults to /var/tmp.
  • On Windows OS, environment variables TMP and TEMP are evaluated (same as with SpecialFolder::Temp).

If the directory does not exist, then (on all OS), a new directory named ".var.tmp" is created in the user's home directory and returned (if not existent already). If this fails, the home directory itself is returned.

Note
With the potential creation of the directory ".var.tmp" in the user's home directory, a small readme.txt file is created, containing the name of the running application and the reason of the creation.

To overrule this behavior, public static variable evaluatedVarTempDir may be set arbitrarily prior to using this enum value.

Definition at line 51 of file directory.hpp.

Field Details:

◆ evaluatedTempDir

AString evaluatedTempDir
static

Singleton containing the path for the use of enum value SpecialFolder::Temp. This is evaluated once with the first use of SpecialFolder::Temp. To change the default behavior of evaluation, this variable may be filled with a proper path prior to using enum SpecialFolder::Temp.

Definition at line 126 of file directory.hpp.

◆ evaluatedVarTempDir

AString evaluatedVarTempDir
static

Singleton containing the path for the use of enum value SpecialFolder::VarTemp. This is evaluated once with the first use of SpecialFolder::VarTemp. To change the default behavior of evaluation, this variable may be filled with a proper path prior to using enum SpecialFolder::VarTemp.

Definition at line 135 of file directory.hpp.

◆ Path

AString Path

The path of the directory represented by this instance

Definition at line 138 of file directory.hpp.

Constructor(s) / Destructor Details::

◆ Directory() [1/3]

Directory ( )
inline

Constructs an object representing no directory. Field Path remains empty.

Definition at line 148 of file directory.hpp.

◆ Directory() [2/3]

Directory ( SpecialFolder special)
inline

Constructs an object representing one of the known special directories.

Parameters
specialThe special directory to initialize this instance to.

Definition at line 155 of file directory.hpp.

Here is the call graph for this function:

◆ Directory() [3/3]

Directory ( const String & path)
inline

Constructs an object representing the given path.

Parameters
pathThe initial path. If this is a relative path, it relates to the processes current directory.

Definition at line 165 of file directory.hpp.

Here is the call graph for this function:

Method Details:

◆ Change() [1/3]

bool Change ( const CString & path)

Changes the directory. If the given path is relative (e.g. a name of a sub directory or ".."), such path is added to the current Path. Otherwise, field Path is replaced. If the resulting destination directory is not valid, false is returned and the field Path stays intact.

Parameters
pathThe relative or absolute path to change to.
Returns
true if the change was successful, false otherwise.

Definition at line 251 of file directory.cpp.

Here is the call graph for this function:

◆ Change() [2/3]

bool Change ( const StringNZT & path)

Overloaded version of Change(const CString&) accepting a non-zero-terminated string.

Parameters
pathThe relative or absolute path to change to.
Returns
true if the change was successful, false otherwise.

Definition at line 276 of file directory.cpp.

Here is the call graph for this function:

◆ Change() [3/3]

void Change ( SpecialFolder special)

Changes the directory to one of the known special directories.

Parameters
specialThe special directory to change this instance to.

Definition at line 88 of file directory.cpp.

Here is the call graph for this function:

◆ Create()

SystemErrors Create ( const CString & path)
static

Creates the directory of the given (absolute or relative) path.

Parameters
pathZero-terminated string defining the path to test.
Returns
A value of enum type SystemErrors .

Definition at line 364 of file directory.cpp.

◆ CurrentDirectory()

bool CurrentDirectory ( AString & target)
static

Returns the actual directory in the file system associated with the current process.

Parameters
targetThe target AString to store the directory. Will be cleared in any case
Returns
true on success, false on failure.

Definition at line 314 of file directory.cpp.

Here is the call graph for this function:

◆ Exists() [1/2]

bool Exists ( const CString & path)
static

Tests if the given (absolute or relative) path represents a directory in the file system.

Parameters
pathZero-terminated string defining the path to test.
Returns
true if a directory was found.

Definition at line 334 of file directory.cpp.

◆ Exists() [2/2]

static bool Exists ( const StringNZT & path)
inlinestatic

Overloaded version of Change(const CString&) accepting a non-zero-terminated string.

Parameters
pathThe relative or absolute path to change to.
Returns
true if the change was successful, false otherwise.

Definition at line 225 of file directory.hpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: