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 combinePath (const String &inFolderPath, const String &inFileName)
 
String createTempFileName (const String &inFileName)
 
String createTempFileAndGetFullPath ()
 
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)
 
bool createDirectoryTree (const String &inDirectoryName)
 

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

String Celartem::FileUtils::combinePath ( const String &  inFolderPath,
const String &  inFileName 
)

This function combines path and filename using platform specific path separator.

Parameters
inFolderPathFolder path.
inFileNameFile name to combine to the tail of the folder path.
Returns
The result path.
bool Celartem::FileUtils::copyFile ( const String &  inSrc,
const String &  inDest,
bool  forceOverwrite = false 
)

This function duplicates the specified file.

Parameters
inSrcFile name that specifies the file to be copied.
inDestDestination file name.
forceOverwriteif 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().

bool Celartem::FileUtils::createDirectoryTree ( const String &  inDirectoryName)

This function creates the specified directory tree.

Parameters
inDirectoryNameThe directory to create.
Returns
true if the directory is created successfully; otherwise false.
String Celartem::FileUtils::createTempFileAndGetFullPath ( )

This function creates a temporary file on temporary directory and returns its full path.

Returns
The file path of the newly created temporary file.
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
inFileNameA 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
inFileNameA file to be deleted.
Returns
true if success, otherwise false.

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

bool Celartem::FileUtils::doesExist ( const String &  inFileName)

This function checks whether the specified file exists or not.

Parameters
inFileNameA file to check the existence.
Returns
true if the file exists, otherwise false.

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

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
inPathNameAny path name for a file.
Returns
The extension.

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

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

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

Parameters
inPathNameAny 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
inFileNameAny 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
inFileNameA 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
inPathA path to check.
Returns
true if the path is a directory, otherwise false.

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

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 \c ../ or \c ./ .
        - 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 \c / or \c \\ is removed.

        In Windows, the normalization process also does:

        - It converts the file name into the long file name (if available).
        - All \c / characters in the path are replaced with \c \\ .

        \param inPathName
            Any path name for a file.
        \return
            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
inPathNameAny 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
inPathNameAny path name for a file.
Returns
The result path.

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

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
inPathNameAny path name for a file.
Returns
The result path.

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

bool Celartem::FileUtils::replaceFile ( const String &  inReplacee,
const String &  inReplacer 
)

This function replaces one file with another.

Parameters
inReplaceeFile name that specifies the file to be replaced.
inReplacerFile 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
inFileNameThe file to be used as a temporary file.
inTemporarytrue to use as a temporary file.

Cuminas DjVu SDK 3.0.33103
This document is made with doxygen 1.8.5 at Sun Dec 15 2013 19:38:07.
Cuminas Logo