Provides common operations on files. More...

#include <cxxtools/file.h>

Public Member Functions

 File (const std::string &path)
 Constructs a File object from the path path.
 File (const FileInfo &fi)
 Constructs a File object from a FileInfo object.
 File (const File &file)
 Copy constructor.
 ~File ()
 Destrctor.
Fileoperator= (const File &file)
 Assignment operator.
const std::string & path () const
 Returns the full path of file in the file-system.
std::size_t size () const
 Returns the size of the file in bytes.
std::string dirName () const
 Returns the parent directory path.
std::string name () const
 Returns the file name including an exension.
std::string baseName () const
 Returns the file name without the exension.
std::string extension () const
 Returns the file name extension or an empty string if not present.
void resize (std::size_t n)
 Resizes the file to a new size of n bytes.
void remove ()
 Removes the file.
void move (const std::string &to)
 Moves the file to the location given by to.
void link (const std::string &newpath)
void symlink (const std::string &newpath)
void copy (const std::string &newpath)

Static Public Member Functions

static File create (const std::string &path)
 Creates a new file at the path given by path.
static bool exists (const std::string &path)
 Returns true if a file exists at path, or false otherwise.

Protected Member Functions

 File ()
 Default Constructor.

Detailed Description

Provides common operations on files.

Constructor & Destructor Documentation

cxxtools::File::File ( const std::string &  path)
explicit

Constructs a File object from the path path.

If no file exists at path, an exception of type FileNotFound is thrown.

cxxtools::File::File ( const FileInfo fi)
explicit

Constructs a File object from a FileInfo object.

An exception of type FileNotFound is thrown if the FileInfo does not represent a file.

cxxtools::File::File ( const File file)

Copy constructor.

cxxtools::File::~File ( )

Destrctor.

cxxtools::File::File ( )
protected

Default Constructor.

Member Function Documentation

std::string cxxtools::File::baseName ( ) const

Returns the file name without the exension.

void cxxtools::File::copy ( const std::string &  newpath)
static File cxxtools::File::create ( const std::string &  path)
static

Creates a new file at the path given by path.

std::string cxxtools::File::dirName ( ) const

Returns the parent directory path.

This method might return an empty string if the node was created without a complete path. If the directory is located in the root directory of a unix file system, a slash ("/") is returned. A returned directory path always ends with a trailing path separator character. (A backslash in Windows and a slash in Unix, for example.)

static bool cxxtools::File::exists ( const std::string &  path)
static

Returns true if a file exists at path, or false otherwise.

std::string cxxtools::File::extension ( ) const

Returns the file name extension or an empty string if not present.

void cxxtools::File::link ( const std::string &  newpath)
void cxxtools::File::move ( const std::string &  to)

Moves the file to the location given by to.

The File object will stay valid after this method was called and point to the moved file.

std::string cxxtools::File::name ( ) const

Returns the file name including an exension.

File& cxxtools::File::operator= ( const File file)

Assignment operator.

const std::string& cxxtools::File::path ( ) const
inline

Returns the full path of file in the file-system.

This method may return a relative path, or a fully qualified one depending on how this object was constructed.

void cxxtools::File::remove ( )

Removes the file.

This object will be invalid after calling this method.

void cxxtools::File::resize ( std::size_t  n)

Resizes the file to a new size of n bytes.

std::size_t cxxtools::File::size ( ) const

Returns the size of the file in bytes.

void cxxtools::File::symlink ( const std::string &  newpath)

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