36 DWORD sz = ::GetCurrentDirectory(0, NULL);
37 if (sz > 0 && (sz = ::GetCurrentDirectory(sz, outpath.
advBuffer(sz))) > 0)
42 const size_t DEFAULT_BUF_SIZE = 512;
43 for (
size_t sz = DEFAULT_BUF_SIZE;; sz *= 2) {
45 const char* p = ::getcwd(outpath.
advBuffer(sz), sz);
47 assert( p == outpath.
data() );
50 }
else if (errno != ERANGE) {
72 if (::SetCurrentDirectory(path) != 0)
76 if (::chdir(path) == 0)
78 const int code = errno;
80 case EACCES: err =
EAccess;
break;
81 case EFAULT: err =
EPtr;
break;
83 case ENAMETOOLONG: err =
ESize;
break;
85 case ENOTDIR: err =
ENotDir;
break;
86 default: err =
EFail;
break;
108 return outpath.
set();
174 return (error_ !=
ENone);
202 return (dir_.handle != NULL);
213 error_ = dir_.open(path);
215 return error_ ==
ENone;
239 return dir_.read(entry);
242 #if !defined(_WIN32) || defined(DOXYGEN) bool chdir()
Change current working directory to currently open directory (Linux/Unix only).
Definition: dir.h:246
Error error() const
Get error code from last operation.
Definition: dir.h:194
Directory(const char *path, bool excep=1)
Constructor to open directory.
Definition: dir.h:163
Permission denied.
Definition: sys.h:1135
Invalid pointer used.
Definition: sys.h:1133
void advSize(Size size)
Advanced: Set new size after writing directly to buffer.
Definition: list.h:2754
static String & join(String &basepath, const SubString &addpath)
Join two paths together.
Definition: filepath.h:739
bool operator!() const
Negation operator checks whether an error was set by a previous operation.
Definition: dir.h:173
bool read(SubString &entry)
Read next directory entry.
Definition: dir.h:238
Directory reader.
Definition: dir.h:149
#define EVO_ONCPP11(EXPR)
Compile EXPR only if C++11 support is detected, otherwise this is a no-op.
Definition: sys.h:259
#define EVO_CREATE_EXCEPTION_IMPL(NAME, BASE)
Create an Evo exception implementation.
Definition: sys.h:1365
#define EVO_THROW_ERR_CHECK(TYPE, MSG, ERROR, COND)
Throw an Evo exception with error code if COND is true.
Definition: sys.h:1513
System directory reader (used internally).
Definition: sysio_dir.h:40
Error set_cwd(const char *path, bool excep=1)
Set current working directory.
Definition: dir.h:69
Resource not found.
Definition: sys.h:1137
Size limit exceeded.
Definition: sys.h:1139
No error.
Definition: sys.h:1115
#define EVO_EXCEPTIONS
Whether to throw exceptions on error by default.
Definition: evo_config.h:35
Error
General Evo error code stored in exceptions, or used directly when exceptions are disabled...
Definition: sys.h:1113
String & get_cwd(String &outpath)
Store current working directory in string.
Definition: dir.h:33
Evo system I/O implementation for directories.
const char * data() const
Get string pointer (const).
Definition: string.h:1533
bool excep() const
Get whether exceptions are enabled.
Definition: dir.h:180
static bool abs(const SubString &path, bool strict=true)
Check whether path is an absolute path.
Definition: filepath.h:113
String container.
Definition: string.h:674
void excep(bool val)
Set whether exceptions are enabled.
Definition: dir.h:187
Safe bool base class.
Definition: type.h:73
Directory(bool excep=1)
Constructor.
Definition: dir.h:154
void close()
Close currently open directory, if any.
Definition: dir.h:219
Evo base exception class.
Definition: sys.h:1214
Evo UnicodeString container.
Evo C++ Library namespace.
Definition: alg.h:11
Directory open exception for errors opening a directory for reading entries, see Exception.
Definition: dir.h:121
static String & normalize(String &outpath, const SubString &path)
Normalize path and remove redundant components.
Definition: filepath.h:267
Operation failed.
Definition: sys.h:1124
T * advBuffer(Size size)
Advanced: Resize and get buffer pointer (modifier).
Definition: list.h:2728
bool null() const
Get whether null.
bool open(const char *path)
Open directory for reading entries.
Definition: dir.h:212
String & set()
Set as null and empty.
Definition: string.h:995
Path component is not a directory.
Definition: sys.h:1138
String & get_abspath(String &outpath, SubString &path)
Get absolute path for given input path.
Definition: dir.h:106
Reference and access existing string data.
Definition: substring.h:229
void seek()
Seek to beginning of directory.
Definition: dir.h:227
Evo file path operations.
bool isopen() const
Get whether directory is open.
Definition: dir.h:201
String & reserve(Size size, bool prefer_realloc=false)
Reserve capacity for additional items (modifier).
Definition: string.h:5027