Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

lrt::File Class Reference

The class File defines a file descriptor in a system-independent manner. More...

#include <rtfile.h>

List of all members.

Public Methods

 File ()
 Creates an invalid file descriptor.

 File (const String &name)
 Creates a file descriptor for the given file name. More...

 File (const File &)
 Creates a file descriptor by copying over the given one.

 File (const File &parent, const String &child)
 Creates a file descriptor for the given file name. More...

File & operator= (const File &)
 Copies all data over from the given file descriptor.

 ~File ()
String getName () const
 Returns the absolute file name, using the system's path separator, of this file.

String getFileName () const
 Returns the file name, relative to the folder in which it is contained. More...

String getLocalName (const File &relFile=(*currentFolder)) const
 Returns a local file name, using the system's path separator, of this file. More...

String getParent () const
 Returns the absolute file name, using the system's path separator, of this file's parent folder.

File getParentFile () const
 Returns a file descriptor for this file's parent folder. More...

bool isFolder () const
 Returns true if this file descriptor denotes a folder.

bool isFile () const
 Returns true if this file descriptor denotes a normal file (and not a folder).

bool exists ()
 Returns true if this file exists.

bool canWrite ()
 Returns true if the application can write to the file denoted by this file descriptor.

bool canRead ()
 Returns true if the application can read from the file denoted by this file descriptor.

int getSize ()
 Returns the file's size, or -1 if it does not exist.

Time getLastModified ()
 Returns the file's last modification date, or the epoch if it doesn't exist.

InputStream * openRead (bool textMode)
 Opens this file for reading, if it exists. More...

OutputStream * openWrite ()
 Opens this file for overwriting, if it exists and can be written to.

OutputStream * openAppend ()
 Opens this file for appending, if it exists and can be written to.

Array< File > list ()
 Lists all files and folders contained in this folder. More...

Array< File > list (const IFilenameFilter *)
 Lists all files and folders contained in this folder which match the given filename filter. More...


Static Public Methods

void setCurrentFolder (const File &newFolder)
 Sets the "current folder" to the given new folder. More...

const String getCurrentFolder ()
 Returns the "current folder". More...

const File getExecutableFile ()
 Returns the executable program's file name (if available). More...

const File getHomeFolder ()
 Returns a file descriptor for the current user's home folder. More...

const File getSettingsFolder ()
 Returns a file descriptor for the current user's LRT settings folder. More...

bool createFolder (const File &folder)
 Creates the folder as given by its file descriptor. More...

void initialize (const String &executableFileName)
 Initializes the File class. More...

void finalize ()
 Finalizes the File class. More...

bool isAbsolute (const String &fname)
 Checks if the given file name is absolute.


Static Public Attributes

const char separatorChar = '\\'
 The character used to separate path components in Files. More...

const String separator = "\\"
 The character used to separate path components in Files. More...

const bool caseSensitive = false
 Are file names case sensitive?


Friends

class File::FileAttributes


Detailed Description

The class File defines a file descriptor in a system-independent manner.

It provides methods to query file attributes, open files, and list folders.

When using libRT to open files, you should specify their names separated with forward slashes '/'. The File class will automatically convert them to the system dependent file name separator. Also, when constructing a File which denotes a folder, you must append a slash to its name.

Examples:
"c:/Programs" means the file called "Programs" in folder "c:".
"/usr/bin/" means the folder "bin" in folder "usr", specified as an absolute path.
"test/test.txt" means the file "test.txt" in the subfolder "test" of the current folder (see getCurrentFolder() for this).
"../xyz.txt" means the file "xyz.txt", one folder up from the current folder.


Constructor & Destructor Documentation

lrt::File::File (  const String &    name ) 
 

Creates a file descriptor for the given file name.

If the given name is not absolute, it is resolved against the current folder.

lrt::File::File (  const File &    parent,
const String &    child
) 
 

Creates a file descriptor for the given file name.

If the name is not absolute, it is resolved against the given parent file descriptor.

Parameters:
parent  The parent file descriptor.
child  The child file name.


Member Function Documentation

bool lrt::File::createFolder (  const File &    folder )  [static]
 

Creates the folder as given by its file descriptor.

If the given file descriptor is a file, its parent is created instead.

Returns:
true if the folder already existed or could be created successfully, false if it couldn't be created.

void lrt::File::finalize (    )  [static]
 

Finalizes the File class.

As this method is automatically called by System::exit(), you should never have to call it yourself from applications.

const String lrt::File::getCurrentFolder (    )  [static]
 

Returns the "current folder".

All relative paths are resolved to this folder.

const File lrt::File::getExecutableFile (    )  [static]
 

Returns the executable program's file name (if available).

Note that the rtMain() method is not passed the executable file name within args.

String lrt::File::getFileName (    )  const
 

Returns the file name, relative to the folder in which it is contained.

(This is the local file name without any folders prefixed.)

const File lrt::File::getHomeFolder (    )  [static]
 

Returns a file descriptor for the current user's home folder.

Under Unix systems, this is the contents of the $HOME environment variable, under Windows, the "My Documents" folder is returned.

String lrt::File::getLocalName (  const File &    relFile = (*currentFolder) )  const
 

Returns a local file name, using the system's path separator, of this file.

Parameters:
relFile  (optional) The folder against which the localization should be performed.

File lrt::File::getParentFile (    )  const
 

Returns a file descriptor for this file's parent folder.

If this file descriptor already denotes a root folder, it is returned unchanged.

const File lrt::File::getSettingsFolder (    )  [static]
 

Returns a file descriptor for the current user's LRT settings folder.

This folder may be used to store application preferences and settings files. Under Unix, this is the $HOME/.lrt/ folder, on Windows it is either the "Application Data" folder (W2K etc.) or the program's folder. Note that you may have to create the settings folder first using createFolder().

void lrt::File::initialize (  const String &    executableFileName )  [static]
 

Initializes the File class.

You should never call this method from applications.
Implementation note: Must ensure that all static Files are set up to something.

Array< File > lrt::File::list (  const IFilenameFilter *    ) 
 

Lists all files and folders contained in this folder which match the given filename filter.


You should not assume that the returned array is in any particular order.

Array< File > lrt::File::list (    ) 
 

Lists all files and folders contained in this folder.

If this file descriptor does not denote a folder, the contents of its parent folder are returned instead. If this file doesn't exist, a zero-length array is returned.
You should not assume that the returned array is in any particular order.

InputStream * lrt::File::openRead (  bool    textMode ) 
 

Opens this file for reading, if it exists.

You should always call fail() on the returned stream before using it to check if it was opened properly.

Parameters:
textMode  If you want to read text data (as opposed to binary data) from the stream, you should set this flag.

void lrt::File::setCurrentFolder (  const File &    newFolder )  [static]
 

Sets the "current folder" to the given new folder.

The current folder is the one, to which all relative paths are resolved.
Example: If the current folder is c:\Programs\ and you open file ../test.dat, in fact, c:\\test.dat will be opened.


Member Data Documentation

const String lrt::File::separator = "\\" [static]
 

The character used to separate path components in Files.

Represented as a String for your convenience.

const char lrt::File::separatorChar = '\\' [static]
 

The character used to separate path components in Files.

For example, it is '/' in Unix, and '\' in Windows.


The documentation for this class was generated from the following files:
This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer