Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

util::io::File Class Reference

#include <File.h>

List of all members.


Detailed Description

The File class contains static methods for various filesystem-related purposes.


Static Public Methods

void mkdir (std::string path, mode_t mode) throw (IOException&)
 Create a directory.

void remove (std::string path) throw (IOException&)
 Remove a file or directory.

void rename (std::string oldName, std::string newName) throw (IOException&)
 Rename a file.

void chmod (std::string path, mode_t mode) throw (IOException&)
 Change the mode of a file.

mode_t getMode (std::string path) throw (IOException&)
 Get the mode of a file.

bool isDirectory (std::string path) throw (IOException&)
 Check if the file denoted by path is a directory.

bool isFile (std::string path) throw (IOException&)
 Check if the file denoted by path is a regular file.

bool isCharDevice (std::string path) throw (IOException&)
 Check if the file denoted by path is a character device.

bool isBlockDevice (std::string path) throw (IOException&)
 Check if the file denoted by path is a block device.

bool isFifo (std::string path) throw (IOException&)
 Check if the file denoted by path is a FIFO.

bool isLink (std::string path) throw (IOException&)
 Check if the file denoted by path is a symbolic link.

bool isSocket (std::string path) throw (IOException&)
 Check if the file denoted by path is a socket.

void chown (std::string path, std::string owner) throw (IOException&)
 Change the owner of a file.

void chgrp (std::string path, std::string group) throw (IOException&)
 Change the group of a file.

bool exists (std::string path) throw (IOException&)
 Check if a file exists.

off_t getSize (std::string path) throw (IOException&)
 Get the size of a file in bytes.

nlink_t getLinks (std::string path) throw (IOException&)
 Get the number of hard links that point to a file.

std::string getOwner (std::string path) throw (IOException&)
 Get the name of the owner of a file.

std::string getGroup (std::string path) throw (IOException&)
 Get the name of the group of a file.

uid_t getOwnerID (std::string path) throw (IOException&)
 Get the ID of the owner of a file.

gid_t getGroupID (std::string path) throw (IOException&)
 Get the ID of the group of a file.

time_t getAccessTime (std::string path) throw (IOException&)
 Get the time of the last access to a file.

time_t getChangeTime (std::string path) throw (IOException&)
 Get the time of the last modification of a file stats.

time_t getModificationTime (std::string path) throw (IOException&)
 Get the time of the last change to the contents of a file.

std::string baseName (std::string path)
 Get the base name of a path.

std::string dirName (std::string path)
 Get the directory name of a path.

void setWorkDir (std::string path) throw (IOException&)
 Change current working directory.

std::string getWorkDir () throw (IOException&)
 Get current working directory.

List< std::string > listDir (std::string path, int blockSize=128) throw (IOException&)
 Return the names of files in a directory.

List< std::string > wildCard (std::string pattern) throw (IOException&)
 Return the names of files matching a wildcard pattern.

std::string readContents (std::string file) throw (IOException&)
 Read the contents of a file as a string.

util::Blob< char > readBlob (std::string file) throw (IOException&)
 Read the contents of a file as a Blob.

List< std::string > readLines (std::string file, int blockSize=128) throw (IOException&)
 Read the lines of a text file as a list of strings.


Member Function Documentation

string util::io::File::baseName std::string    path [static]
 

Get the base name of a path.

See basename(3) for details.

void util::io::File::chmod std::string    path,
mode_t    mode
throw (IOException&) [static]
 

Change the mode of a file.

The mode of a file is most easily formed by a logical OR operation of some of the following: <th>Constant</th><th>Value</th><th>Description</th>
S_ISUID04000Set user ID on execution.
S_ISGID020#0Set group ID on execution if # is 7, 5, 3, or 1.
Enable mandatory file/record locking if # is 6, 4, 2, or 0.
S_ISVTX01000Save text image after execution.
S_IRWXU00700Read, write, execute by owner.
S_IRUSR00400Read by owner.
S_IWUSR00200Write by owner.
S_IXUSR00100Execute (search if a directory) by owner.
S_IRWXG00070Read, write, execute by group.
S_IRGRP00040Read by group.
S_IWGRP00020Write by group.
S_IXGRP00010Execute by group.
S_IRWXO00007Read, write, execute (search) by others.
S_IROTH00004Read by others.
S_IWOTH00002Write by others.
S_IXOTH00001Execute by others.

For example, chmod("foo.bar",S_IRUSR | S_IWUSR) sets read and write permissions to the owner of file "foo.bar".

string util::io::File::dirName std::string    path [static]
 

Get the directory name of a path.

See basename(3) for details.

mode_t util::io::File::getMode std::string    path throw (IOException&) [static]
 

Get the mode of a file.

See also:
chmod(string, mode_t)

off_t util::io::File::getSize std::string    path throw (IOException&) [static]
 

Get the size of a file in bytes.

In many cases, it is useful to cast the returned value to an int.

List< string > util::io::File::listDir std::string    path,
int    blockSize = 128
throw (IOException&) [static]
 

Return the names of files in a directory.

Use the blockSize parameter to adjust the performance of the method. Larger blockSize means more memory is initially allocated to store the directory entries.

void util::io::File::mkdir std::string    path,
mode_t    mode
throw (IOException&) [static]
 

Create a directory.

Parameters:
path  the name of the directory
mode  the mode of the file
See also:
chmod(string, mode_t)

Blob< char > util::io::File::readBlob std::string    file throw (IOException&) [static]
 

Read the contents of a file as a Blob.

The pointer stored into the returned blob is allocated with malloc(), and must be released by the caller.

List< string > util::io::File::readLines std::string    file,
int    blockSize = 128
throw (IOException&) [static]
 

Read the lines of a text file as a list of strings.

Use the blockSize parameter to adjust the performance of the method. Use a large value for large files.

void util::io::File::rename std::string    oldName,
std::string    newName
throw (IOException&) [static]
 

Rename a file.

A file can be "renamed" to another directory, effectively performing a "move" operation.

List< string > util::io::File::wildCard std::string    pattern throw (IOException&) [static]
 

Return the names of files matching a wildcard pattern.

The pattern may contain any familiar shell wild cards. Examples:

 File::wildCard("*.cc"); //matches files with a .cc suffix
 File::wildCard("[fbx-z]*.txt"); //matches foo.txt, bar.txt, x1.txt etc.
 File::wildCard("/home/me/code.{cc,h}"); //matches code.cc and code.h
 


The documentation for this class was generated from the following files:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.