feisty meow concerns codebase  2.140
filesystem::directory Class Reference

Implements a scanner that finds all filenames in the directory specified. More...

#include <directory.h>

Inheritance diagram for filesystem::directory:
Collaboration diagram for filesystem::directory:

Public Member Functions

 directory (const basis::astring &path, const char *pattern="*")
 opens up the "path" specified and scans for files and subdirectories. More...
 
 directory (const directory &to_copy)
 
virtual ~directory ()
 
directoryoperator= (const directory &to_copy)
 
 DEFINE_CLASS_NAME ("directory")
 
bool good () const
 true if the directory existed and its contents were readable. More...
 
const basis::astringpath () const
 returns the directory that we manage. More...
 
const basis::astringpattern () const
 returns the pattern that the directory class scans for. More...
 
bool reset (const basis::astring &path, const char *pattern="*")
 gets rid of any current files and rescans the directory at "path". More...
 
bool move_up (const char *pattern="*")
 resets the directory to be its own parent. More...
 
bool move_down (const basis::astring &subdir, const char *pattern="*")
 changes down into a "subdir" of this directory. More...
 
bool rescan ()
 reads our current directory's contents over again. More...
 
const structures::string_arrayfiles () const
 returns the list of files that we found in this directory. More...
 
const structures::string_arraydirectories () const
 these are the directory names from the folder. More...
 

Static Public Member Functions

static basis::astring absolute_path (const basis::astring &relative_path)
 returns the absolute path to a file with "relative_path". More...
 
static basis::astring current ()
 returns the current directory, as reported by the operating system. More...
 
static bool make_directory (const basis::astring &path)
 returns true if the directory "path" could be created. More...
 
static bool remove_directory (const basis::astring &path)
 returns true if the directory "path" could be removed. More...
 
static bool recursive_create (const basis::astring &directory_name)
 returns true if the "directory_name" can be created or already exists. More...
 

Detailed Description

Implements a scanner that finds all filenames in the directory specified.

Definition at line 26 of file directory.h.

Constructor & Destructor Documentation

◆ directory() [1/2]

filesystem::directory::directory ( const basis::astring path,
const char *  pattern = "*" 
)

opens up the "path" specified and scans for files and subdirectories.

if the location was accessible, then the good() method returns true. note that the "path" should just be a bare directory without any wildcards attached. the "pattern" can be specified if you wish to strain out just a subset of the files in the directory. it must meet the same requirements that the operating system places on wildcard patterns.

Definition at line 64 of file directory.cpp.

References path(), pattern(), and reset().

◆ directory() [2/2]

filesystem::directory::directory ( const directory to_copy)

Definition at line 72 of file directory.cpp.

References basis::astring::observe(), and reset().

◆ ~directory()

filesystem::directory::~directory ( )
virtual

Definition at line 80 of file directory.cpp.

References basis::WHACK().

Member Function Documentation

◆ absolute_path()

astring filesystem::directory::absolute_path ( const basis::astring relative_path)
static

returns the absolute path to a file with "relative_path".

an empty string is returned on failure.

Definition at line 101 of file directory.cpp.

References MAX_ABS_PATH, and basis::astring::s().

◆ current()

astring filesystem::directory::current ( )
static

returns the current directory, as reported by the operating system.

Definition at line 114 of file directory.cpp.

References MAX_ABS_PATH.

Referenced by move_down(), and move_up().

◆ DEFINE_CLASS_NAME()

filesystem::directory::DEFINE_CLASS_NAME ( "directory"  )

◆ directories()

const string_array & filesystem::directory::directories ( ) const

these are the directory names from the folder.

they can also be examined using the filename object. note that this does not include the entry for the current directory (.) or the parent (..).

Definition at line 145 of file directory.cpp.

Referenced by whacking_spider().

◆ files()

const string_array & filesystem::directory::files ( ) const

returns the list of files that we found in this directory.

these are all assumed to be located in our given path. to find out more information about the files themselves, construct a filename object with the path() and the file of interest.

Definition at line 143 of file directory.cpp.

Referenced by fix_project_references.fix_project_references::replace_all_occurrences(), phrase_replacer.phrase_replacer::replace_all_occurrences(), stamping_spider(), whacking_spider(), and versions::version_ini::write_assembly().

◆ good()

bool filesystem::directory::good ( ) const
inline

true if the directory existed and its contents were readable.

Definition at line 46 of file directory.h.

Referenced by filesystem::directory_tree::reset().

◆ make_directory()

bool filesystem::directory::make_directory ( const basis::astring path)
static

returns true if the directory "path" could be created.

Definition at line 237 of file directory.cpp.

References mkdir, path(), and basis::astring::s().

Referenced by recursive_create().

◆ move_down()

bool filesystem::directory::move_down ( const basis::astring subdir,
const char *  pattern = "*" 
)

changes down into a "subdir" of this directory.

the "subdir" should be just the file name component to change into. absolute paths will not work. for example, if a directory "/l/jed" has a subdirectory named "clampett", then use:

my_dir->move_down("clampett")

Definition at line 137 of file directory.cpp.

References current(), pattern(), and reset().

◆ move_up()

bool filesystem::directory::move_up ( const char *  pattern = "*")

resets the directory to be its own parent.

Definition at line 131 of file directory.cpp.

References current(), pattern(), and reset().

◆ operator=()

directory & filesystem::directory::operator= ( const directory to_copy)

Definition at line 93 of file directory.cpp.

References basis::astring::observe(), and reset().

◆ path()

const astring & filesystem::directory::path ( ) const

returns the directory that we manage.

Definition at line 89 of file directory.cpp.

Referenced by directory(), make_directory(), remove_directory(), reset(), stamping_spider(), and whacking_spider().

◆ pattern()

const astring & filesystem::directory::pattern ( ) const

returns the pattern that the directory class scans for.

Definition at line 91 of file directory.cpp.

Referenced by directory(), move_down(), move_up(), and reset().

◆ recursive_create()

bool filesystem::directory::recursive_create ( const basis::astring directory_name)
static

returns true if the "directory_name" can be created or already exists.

false returns indicate that the operating system wouldn't let us make the directory, or that we didn't have sufficient permissions to access an existing directory to view it or move into it.

Definition at line 257 of file directory.cpp.

References basis::astring::end(), filesystem::filename::exists(), FUNCDEF, filesystem::filename::is_directory(), filesystem::filename::join(), basis::array< contents >::length(), make_directory(), filesystem::filename::raw(), filesystem::filename::separate(), and basis::array< contents >::subarray().

Referenced by filesystem::heavy_file_operations::copy_file(), filesystem::directory_tree::make_directories(), and filesystem::heavy_file_operations::write_file_chunk().

◆ remove_directory()

bool filesystem::directory::remove_directory ( const basis::astring path)
static

returns true if the directory "path" could be removed.

Definition at line 247 of file directory.cpp.

References path(), rmdir, and basis::astring::s().

◆ rescan()

◆ reset()

bool filesystem::directory::reset ( const basis::astring path,
const char *  pattern = "*" 
)

gets rid of any current files and rescans the directory at "path".

a new "pattern" can be specified at this time also.

Definition at line 128 of file directory.cpp.

References path(), pattern(), and rescan().

Referenced by directory(), move_down(), move_up(), and operator=().


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