Scopira  20080306
scopira::tool::file Class Reference

#include <file.h>

Public Types

typedef ::off_t offset_t
 

Public Member Functions

 file (void)
 default ctor and copy are fine
 
 file (const std::string &fname)
 
void set (const std::string &fname)
 
bool exists (void) const
 
bool is_file (void) const
 
bool is_dir (void) const
 
offset_t size (void) const
 

Static Public Member Functions

static bool check_path (const std::string &path)
 
static bool has_ext (const std::string &fname, const std::string &ext)
 
static void expand_homedir (std::string &path)
 
static void expand_envvar (std::string &path)
 
static void split_ext (const std::string &fullname, std::string &sansext, std::string &ext)
 
static void split_path (const std::string &fullname, std::string &path, std::string &name)
 
static std::string realpath (const std::string &name)
 
static void create_directory (const std::string &dirname)
 

Detailed Description

File class. use to get information about a file on disk (kinda like the Java class by the same name)

This should probably be eventually upgraded to stat64 and int64_t (especialy for size()).

Author
Aleksander Demko

Constructor & Destructor Documentation

◆ file()

scopira::tool::file::file ( const std::string &  fname)

ctor. this object is mostly const-ish

Author
Aleksander Demko

Member Function Documentation

◆ check_path()

static bool scopira::tool::file::check_path ( const std::string &  path)
static

check if the given path is nice. nice means, no "/."

Returns
true if string is clean/ok

◆ create_directory()

static void scopira::tool::file::create_directory ( const std::string &  dirname)
static

Creates a directory.

Author
Aleksander Demko

◆ exists()

bool scopira::tool::file::exists ( void  ) const

Does this "file" exist? In this context, file can be anything (eg directory, symlink, etc)

Author
Aleksander Demko

◆ expand_envvar()

static void scopira::tool::file::expand_envvar ( std::string &  path)
static

Find all references to $ENVVAR and replace them with the corresponding variable from the environment.

Author
Aleksander Demko

◆ expand_homedir()

static void scopira::tool::file::expand_homedir ( std::string &  path)
static

expand the give path for home directory references. in particular, [0] == '~', replace it with $HOME (home directory)

Author
Aleksander Demko

◆ has_ext()

static bool scopira::tool::file::has_ext ( const std::string &  fname,
const std::string &  ext 
)
static

check if the file ends (case insensitivly) with the given exntesion. ext must be all upper case. Example: ".XML". The "extension" may have multiple periods (this function just does a end-string comparison – periods have no special meaning)

Author
Aleksander Demko

◆ is_dir()

bool scopira::tool::file::is_dir ( void  ) const

Is it a directory?

Author
Aleksander Demko

◆ is_file()

bool scopira::tool::file::is_file ( void  ) const

Is this a file?

Author
Aleksander Demko

◆ realpath()

static std::string scopira::tool::file::realpath ( const std::string &  name)
static

Wrapper around stdlib realpath(). Mainly, removes the trailing / or \, removes . or .. and resolves all symbolice links.

Author
Aleksander Demko

◆ set()

void scopira::tool::file::set ( const std::string &  fname)

set it to a new file

Author
Aleksander Demko

◆ size()

offset_t scopira::tool::file::size ( void  ) const

return the size, in bytes

Author
Aleksander Demko

◆ split_ext()

static void scopira::tool::file::split_ext ( const std::string &  fullname,
std::string &  sansext,
std::string &  ext 
)
static

Splits a full path from its extension. For example, /path/filename.ext will be split into /path/filename and .ext.

Author
Aleksander Demko

◆ split_path()

static void scopira::tool::file::split_path ( const std::string &  fullname,
std::string &  path,
std::string &  name 
)
static

Splits a filename from it's path. For example, /path/filename.ext becomes /path/ and filename.ext.

Author
Aleksander Demko

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