30 #include "../algorithms/sorts.h"
31 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
55 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
58 using namespace basis;
64 directory::directory(
const astring &
path,
const char *pattern)
65 : _scanned_okay(false),
73 : _scanned_okay(false),
82 _scanned_okay =
false;
95 if (
this == &to_copy)
return *
this;
96 _scanned_okay =
false;
109 if (!realpath(rel_path.
s(), abs_path))
return "";
123 if (realpath(
".", buffer)) to_return = buffer;
150 _scanned_okay =
false;
201 DIR *dir = opendir(_path->
s());
203 if (!dir)
return false;
204 dirent *entry = readdir(dir);
206 char *file = entry->d_name;
208 if (!strcmp(file, cur_dir.
s())) add_it =
false;
209 if (!strcmp(file, par_dir.
s())) add_it =
false;
211 if (add_it && !fnmatch(_pattern->
s(), file, 0)) {
215 LOG(
astring(
"skipping abnormal file: ") + temp_name);
217 entry = readdir(dir);
226 entry = readdir(dir);
233 _scanned_okay =
true;
239 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
249 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
264 for (
int i = 0; i < pieces.
length(); i++) {
268 curr.
join(rooted, partial);
272 curr = curr.
raw() +
"/";
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
array & concatenate(const array &to_concatenate)
Appends the array "to_concatenate" onto "this" and returns "this".
array subarray(int start, int end) const
Returns the array segment between the indices "start" and "end".
contents * access()
A non-constant access of the underlying C-array. BE REALLY CAREFUL.
int length() const
Returns the current reported length of the allocated C array.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
int end() const
returns the index of the last (non-null) character in the string.
virtual const char * observe() const
observes the underlying pointer to the zero-terminated string.
Implements a scanner that finds all filenames in the directory specified.
directory(const basis::astring &path, const char *pattern="*")
opens up the "path" specified and scans for files and subdirectories.
bool move_down(const basis::astring &subdir, const char *pattern="*")
changes down into a "subdir" of this directory.
static basis::astring absolute_path(const basis::astring &relative_path)
returns the absolute path to a file with "relative_path".
static bool recursive_create(const basis::astring &directory_name)
returns true if the "directory_name" can be created or already exists.
const structures::string_array & directories() const
these are the directory names from the folder.
static bool remove_directory(const basis::astring &path)
returns true if the directory "path" could be removed.
directory & operator=(const directory &to_copy)
const structures::string_array & files() const
returns the list of files that we found in this directory.
const basis::astring & path() const
returns the directory that we manage.
bool move_up(const char *pattern="*")
resets the directory to be its own parent.
const basis::astring & pattern() const
returns the pattern that the directory class scans for.
static basis::astring current()
returns the current directory, as reported by the operating system.
bool rescan()
reads our current directory's contents over again.
bool reset(const basis::astring &path, const char *pattern="*")
gets rid of any current files and rescans the directory at "path".
static bool make_directory(const basis::astring &path)
returns true if the directory "path" could be created.
Provides operations commonly needed on file names.
bool exists() const
returns true if the file exists.
void join(bool rooted, const structures::string_array &pieces)
undoes a separate() operation to get the filename back.
void separate(bool &rooted, structures::string_array &pieces) const
breaks the filename into its component parts.
bool is_directory() const
const basis::astring & raw() const
returns the astring that we're holding onto for the path.
An array of strings with some additional helpful methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
void shell_sort(type v[], int n, bool reverse=false)
shell sort algorithm.
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
Support for unicode builds.
Aids in achievement of platform independence.