Classes | Functions

Celartem::FileUtils Namespace Reference

Classes

class  DirectoryListing

Functions

String normalizePath (const String &inFileName)
String getFullPathName (const String &inFileName)
String getFileNameFromPath (const String &inPathName)
String getExtension (const String &inPathName)
String removeFileNameFromPath (const String &inPathName)
String removeExtensionFromPath (const String &inPathName)
String removeTrailingPathSeparator (const String &inPathName)
String createTempFileName (const String &inFileName)
bool doesExist (const String &inFileName)
bool isDirectory (const String &inPath)
bool deleteFile (const String &inFileName)
bool copyFile (const String &inSrc, const String &inDest, bool forceOverwrite=false)
bool replaceFile (const String &inReplacee, const String &inReplacer)
void setTemporaryAttributes (const String &inFileName, bool inTemporary=true)
String getCurrentDirectory ()
String getTemporaryDirectory ()
bool isAbsolutePath (const String &inFileName)

Detailed Description

Utilities for File Manipulation. You had better use Path class instead of directly using the functions provided in the namespace since it may cause some security risks.

See also:
Path

Function Documentation

bool Celartem::FileUtils::copyFile ( const String &  inSrc,
const String &  inDest,
bool  forceOverwrite = false 
)

This function duplicates the specified file.

Parameters:
inSrc File name that specifies the file to be copied.
inDest Destination file name.
forceOverwrite if the parameter is true, then this function overwrites the existing file, otherwise the function fails.
Returns:
true if success, otherwise false.

Referenced by Celartem::Path::overwriteWith().

String Celartem::FileUtils::createTempFileName ( const String &  inFileName  ) 

This function creates a temporary name that is based on the input filename. This function also creates the file to preserve the temporary name.
For example, if you pass "/foo/bar/baz", then it returns "/foo/bar/baz.xxx" or something like it.

Parameters:
inFileName A base file name.
Returns:
The file name of the newly created temporary file.
bool Celartem::FileUtils::deleteFile ( const String &  inFileName  ) 

This function delete the specified file.

Parameters:
inFileName A file to be deleted.
Returns:
true if success, otherwise false.
bool Celartem::FileUtils::doesExist ( const String &  inFileName  ) 

This function checks whether the specified file exists or not.

Parameters:
inFileName A file to check the existence.
Returns:
true if the file exists, otherwise false.
String Celartem::FileUtils::getCurrentDirectory (  ) 

This function returns the path for the current working directory.

Returns:
The path for the current working directory.
String Celartem::FileUtils::getExtension ( const String &  inPathName  ) 

This function returns the extension ".XXX" from the specified path.

Parameters:
inPathName Any path name for a file.
Returns:
The extension.
String Celartem::FileUtils::getFileNameFromPath ( const String &  inPathName  ) 

This function returns the body file name from the specified path.

Parameters:
inPathName Any path name for a file.
Returns:
The body file name.

Referenced by Celartem::Path::getBodyFileName().

String Celartem::FileUtils::getFullPathName ( const String &  inFileName  ) 

This function converts the partial path name (relative path) into full path name.

Parameters:
inFileName Any relative path name of the file.
Returns:
The full path name.
String Celartem::FileUtils::getTemporaryDirectory (  ) 

This function returns the path for the temporary directory.

Returns:
The path for the temporary directory.
bool Celartem::FileUtils::isAbsolutePath ( const String &  inFileName  ) 

This function determines whether the specified file name is an absolute path by syntax checking.
Please note that it does not check the existance of the file.

Parameters:
inFileName A file name.
Returns:
true if it is an absolute file name; otherwise false.
bool Celartem::FileUtils::isDirectory ( const String &  inPath  ) 

This function checks whether the specified path is a directory or not.

Parameters:
inPath A path to check.
Returns:
true if the path is a directory, otherwise false.
String Celartem::FileUtils::normalizePath ( const String &  inFileName  ) 

This function returns the normalized path of the specified file path. A normalized path meets the following conditions:

  • The path does not include any ../ or ./ .
  • The path is an absolute path.
  • Any UCS-4 characters that has some aliases are mapped into a certain character code.
  • It can be a symblic link or shortcut; this function does not resolve any links.
  • Any trailing file separator / or \ is removed.

In Windows, the normalization process also does:

  • It converts the file name into the long file name (if available).
  • All / characters in the path are replaced with \ .
Parameters:
inPathName Any path name for a file.
Returns:
The normalized file name.

You had better validate the file paths after normalizing them using the function. The folloing code checks the file is within the user's home directory or not.

bool isInHomeDir(const String& inFileName)
{
    String home = FileUtils::normalizePath(getHomeDir());
    String path = FileUtils::normalizePath(inFileName);

    // since the file path is normalized, if a file is within the
    // user's home directory, its path should be started from
    // \c /home/XXX/ .
    if(path.findPos(home) == 0)
        return true;
    return false;
}

Referenced by Celartem::Path::assign().

String Celartem::FileUtils::removeExtensionFromPath ( const String &  inPathName  ) 

This function removes the extension (including '.') from the specified path if exists.

Parameters:
inPathName Any path name for a file.
Returns:
The result path.

Referenced by Celartem::Path::removeExtension().

String Celartem::FileUtils::removeFileNameFromPath ( const String &  inPathName  ) 

This function removes the body file name from the specified path. If you pass "C:\foo\bar\baz" for the function, it returns "C:\foo\bar\" and never removes the last '\' from the path. On Windows, this function also works with '/' path separator.

Parameters:
inPathName Any path name for a file.
Returns:
The result path.
String Celartem::FileUtils::removeTrailingPathSeparator ( const String &  inPathName  ) 

This function removes the traling path separator from the specified path. If you pass "C:\foo\bar\baz\" for the function, it returns "C:\foo\bar\baz". On Windows, this function also works with '/' path separator.

Parameters:
inPathName Any path name for a file.
Returns:
The result path.
bool Celartem::FileUtils::replaceFile ( const String &  inReplacee,
const String &  inReplacer 
)

This function replaces one file with another.

Parameters:
inReplacee File name that specifies the file to be replaced.
inReplacer File name that specifies the file that overwrites the file.
Returns:
true if success, otherwise false.

Referenced by Celartem::Path::replaceWith().

void Celartem::FileUtils::setTemporaryAttributes ( const String &  inFileName,
bool  inTemporary = true 
)

This function optimizes the file for temporary use.

Parameters:
inFileName The file to be used as a temporary file.
inTemporary true to use as a temporary file.

This document is made with doxygen 1.7.1 at Thu Feb 17 2011 15:40:21.
Caminova Logo