All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::FileUtils Class Reference

FileUtils contains functions for platform independent file-handing. More...

#include <Radiant/FileUtils.hpp>

Static Public Member Functions

static QString baseFilename (const QString &filepath)
 Extract the base filename. More...
 
static QString baseFilenameWithPath (const QString &filepath)
 Extract the base filename. More...
 
static FILE * createFilePath (const QString &filePath)
 Opens the given file for writing and creates the directories in the path if they don't exist. More...
 
static QString directorySeparator ()
 Returns the directory separator for the current platform. More...
 
static bool fileAppendable (const QString &filename)
 Check if the user can append to a given file. More...
 
static QString filename (const QString &filepath)
 Extract filename. More...
 
static bool fileReadable (const QString &filename)
 Check if a given file is readable. More...
 
static QString findFile (const QString &filename, const QString &paths)
 Find a file given a list of paths to search. More...
 
static QString findOverWritable (const QString &filename, const QString &paths)
 Try to find a file that could be over-written. More...
 
static unsigned long getFileLen (std::ifstream &file)
 Get the size of a file. More...
 
static unsigned long getFileLen (const QString &filename)
 Get the size of a file. More...
 
static void indent (FILE *f, int levels)
 Adds indentation space to the given stream. More...
 
static bool isWritable (const QString &path)
 Check if the given file or path is writable. More...
 
static Radiant::TimeStamp lastModified (const QString &filePath)
 Returns seconds from epoch, 0 in case of error. More...
 
static QByteArray loadTextFile (const QString &filename)
 Load a text file. More...
 
static bool looksLikeImage (const QString &filePath)
 Does the given filename look like an image (checks the extension) More...
 
static bool looksLikeVideo (const QString &filePath)
 Does the given filename look like a video (checks the extension) More...
 
static QString path (const QString &filepath)
 Extract path. More...
 
static QString pathSeparator ()
 Returns the path separator for the current platform. More...
 
static bool removeFile (const char *filename)
 Remove a file. More...
 
static bool renameFile (const char *from, const char *to)
 Rename a file. More...
 
static QString suffix (const QString &filepath)
 Extract suffix. More...
 
static QString suffixLowerCase (const QString &filepath)
 Extract suffix, and return it in lower-case. More...
 
static bool suffixMatch (const QString &filename, const QString &suffix)
 Check if a suffix matches. More...
 
static bool writeTextFile (const char *filename, const char *contents)
 Writes a string to a text file. More...
 

Detailed Description

FileUtils contains functions for platform independent file-handing.

Member Function Documentation

static QString Radiant::FileUtils::baseFilename ( const QString &  filepath)
static

Extract the base filename.

Parameters
filepathFull filename with path
Returns
The extracted base filename without suffix or path
static QString Radiant::FileUtils::baseFilenameWithPath ( const QString &  filepath)
static

Extract the base filename.

Parameters
filepathFull filename with path
Returns
The extracted base filename without suffix but with the full path
static FILE* Radiant::FileUtils::createFilePath ( const QString &  filePath)
static

Opens the given file for writing and creates the directories in the path if they don't exist.

Parameters
filePathFull filename with path
Returns
A handle to the open filepath or NULL if the file couldn't be created
static QString Radiant::FileUtils::directorySeparator ( )
static

Returns the directory separator for the current platform.

Returns
Directory separator for the current platform
static bool Radiant::FileUtils::fileAppendable ( const QString &  filename)
static

Check if the user can append to a given file.

This function is useful if you want to overwrite a file, and want to check beforehand that it is possible.

Returns
true if the file exists and can be written to. Otherwise false.
Parameters
filenameName of file
static QString Radiant::FileUtils::filename ( const QString &  filepath)
static

Extract filename.

Parameters
filepathFull filename with path
Returns
The extracted filename of the path
static bool Radiant::FileUtils::fileReadable ( const QString &  filename)
static

Check if a given file is readable.

Parameters
filenameName of file
Returns
true if the specified file is readable
static QString Radiant::FileUtils::findFile ( const QString &  filename,
const QString &  paths 
)
static

Find a file given a list of paths to search.

The directory names are separated by the platform path separator (colon on UNIX, semicolon on Windows) If the file is not found, returns an empty string.

Parameters
filenameName of file
pathsSearch path
Returns
The full path to the found file, or an empty string if it couldn't be found
static QString Radiant::FileUtils::findOverWritable ( const QString &  filename,
const QString &  paths 
)
static

Try to find a file that could be over-written.

If such cannot be found, then return filename.

Parameters
filenameName of file
pathsSearch path
Returns
The full path to the found file, or an empty string if it couldn't be found
static unsigned long Radiant::FileUtils::getFileLen ( std::ifstream &  file)
static

Get the size of a file.

Parameters
fileFile to retrieve length of
Returns
the length of the file. Returns 0 if the file is empty or the file could not be found
static unsigned long Radiant::FileUtils::getFileLen ( const QString &  filename)
static

Get the size of a file.

Parameters
filenameName of file to retrieve length of
Returns
the length of the file. Returns 0 if the file is empty or the file could not be found
static void Radiant::FileUtils::indent ( FILE *  f,
int  levels 
)
static

Adds indentation space to the given stream.

Parameters
fHandle to a file stream
levelsNumber of indentation levels to insert This function is typically used when writing object hierarchies for human-readable output.
static bool Radiant::FileUtils::isWritable ( const QString &  path)
static

Check if the given file or path is writable.

Parameters
pathpath to check
Returns
true if the process can write to the specified path
static Radiant::TimeStamp Radiant::FileUtils::lastModified ( const QString &  filePath)
static

Returns seconds from epoch, 0 in case of error.

Parameters
filePathFull filename with path
Returns
timestamp of last modification or 0 if the time could not be retrieved
static QByteArray Radiant::FileUtils::loadTextFile ( const QString &  filename)
static

Load a text file.

If the reading fails, the returned QByteArray.isNull().

Parameters
filenameName of file
Returns
the contents of the text file
static bool Radiant::FileUtils::looksLikeImage ( const QString &  filePath)
static

Does the given filename look like an image (checks the extension)

Parameters
filePathFull filename with path
Returns
true if the specified file looks like it's an image
static bool Radiant::FileUtils::looksLikeVideo ( const QString &  filePath)
static

Does the given filename look like a video (checks the extension)

Parameters
filePathFull filename with path
Returns
true if the specified file looks like it's a video
static QString Radiant::FileUtils::path ( const QString &  filepath)
static

Extract path.

Parameters
filepathFull filename with path
Returns
the extracted path
static QString Radiant::FileUtils::pathSeparator ( )
static

Returns the path separator for the current platform.

Returns
Path separator for the current platform
static bool Radiant::FileUtils::removeFile ( const char *  filename)
static

Remove a file.

Parameters
filenameName of file
Returns
true if the file was succesfully removed
static bool Radiant::FileUtils::renameFile ( const char *  from,
const char *  to 
)
static

Rename a file.

Parameters
fromSource filename
toDestination filename
Returns
true if the rename was succesful
static QString Radiant::FileUtils::suffix ( const QString &  filepath)
static

Extract suffix.

Parameters
filepathFull filename with path
Returns
The extracted suffix
static QString Radiant::FileUtils::suffixLowerCase ( const QString &  filepath)
static

Extract suffix, and return it in lower-case.

Parameters
filepathFull filename with path
Returns
The extracted lower-case suffix
static bool Radiant::FileUtils::suffixMatch ( const QString &  filename,
const QString &  suffix 
)
static

Check if a suffix matches.

Parameters
filenameName of file
suffixSuffix of file with dot (e.g. ".png")
Returns
true if the suffix matches
static bool Radiant::FileUtils::writeTextFile ( const char *  filename,
const char *  contents 
)
static

Writes a string to a text file.

Parameters
filenameName of output file
contentsString to write to file
Returns
true if the contents have been succesfully written