Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

File Class Reference

Provides common operations on files.

#include <cxxtools/file.h>

List of all members.

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)

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.


Constructor & Destructor Documentation

File ( const std::string &  path  )  [explicit]

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

File ( const FileInfo fi  )  [explicit]

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


Member Function Documentation

const std::string& path (  )  const

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

std::string dirName (  )  const

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.)

void remove (  ) 

This object will be invalid after calling this method.

void move ( const std::string &  to  ) 

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

Copyright © 2008 The Tntnet Development Team
Tntnet 1.6