feisty meow concerns codebase  2.140
directory.h
Go to the documentation of this file.
1 #ifndef DIRECTORY_CLASS
2 #define DIRECTORY_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : directory *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 2001-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
17 
18 #include <basis/astring.h>
19 #include <basis/contracts.h>
21 
22 namespace filesystem {
23 
25 
26 class directory : public virtual basis::root_object
27 {
28 public:
29  directory(const basis::astring &path, const char *pattern = "*");
31 
38  directory(const directory &to_copy);
39 
40  virtual ~directory();
41 
42  directory &operator =(const directory &to_copy);
43 
44  DEFINE_CLASS_NAME("directory");
45 
46  bool good() const { return _scanned_okay; }
48 
49  const basis::astring &path() const;
51 
52  const basis::astring &pattern() const;
54 
55  static basis::astring absolute_path(const basis::astring &relative_path);
57 
59  bool reset(const basis::astring &path, const char *pattern = "*");
61 
63  bool move_up(const char *pattern = "*");
65 
66  bool move_down(const basis::astring &subdir, const char *pattern = "*");
68 
74  bool rescan();
76 
77  const structures::string_array &files() const;
79 
85 
89  // static methods of general directory-related interest.
90 
91  static basis::astring current();
93 
94  static bool make_directory(const basis::astring &path);
96 
97  static bool remove_directory(const basis::astring &path);
99 
100  static bool recursive_create(const basis::astring &directory_name);
102 
106 private:
107  bool _scanned_okay;
108  basis::astring *_path;
109  structures::string_array *_files;
110  structures::string_array *_folders;
111  basis::astring *_pattern;
112 };
113 
114 } //namespace.
115 
116 #endif
117 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Implements a scanner that finds all filenames in the directory specified.
Definition: directory.h:27
DEFINE_CLASS_NAME("directory")
bool good() const
true if the directory existed and its contents were readable.
Definition: directory.h:46
directory(const basis::astring &path, const char *pattern="*")
opens up the "path" specified and scans for files and subdirectories.
Definition: directory.cpp:64
bool move_down(const basis::astring &subdir, const char *pattern="*")
changes down into a "subdir" of this directory.
Definition: directory.cpp:137
static basis::astring absolute_path(const basis::astring &relative_path)
returns the absolute path to a file with "relative_path".
Definition: directory.cpp:101
static bool recursive_create(const basis::astring &directory_name)
returns true if the "directory_name" can be created or already exists.
Definition: directory.cpp:257
const structures::string_array & directories() const
these are the directory names from the folder.
Definition: directory.cpp:145
static bool remove_directory(const basis::astring &path)
returns true if the directory "path" could be removed.
Definition: directory.cpp:247
directory & operator=(const directory &to_copy)
Definition: directory.cpp:93
const structures::string_array & files() const
returns the list of files that we found in this directory.
Definition: directory.cpp:143
const basis::astring & path() const
returns the directory that we manage.
Definition: directory.cpp:89
bool move_up(const char *pattern="*")
resets the directory to be its own parent.
Definition: directory.cpp:131
const basis::astring & pattern() const
returns the pattern that the directory class scans for.
Definition: directory.cpp:91
static basis::astring current()
returns the current directory, as reported by the operating system.
Definition: directory.cpp:114
bool rescan()
reads our current directory's contents over again.
Definition: directory.cpp:147
bool reset(const basis::astring &path, const char *pattern="*")
gets rid of any current files and rescans the directory at "path".
Definition: directory.cpp:128
static bool make_directory(const basis::astring &path)
returns true if the directory "path" could be created.
Definition: directory.cpp:237
An array of strings with some additional helpful methods.
Definition: string_array.h:32
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37