Public Member Functions | Static Public Member Functions

nitro::Directory Class Reference

Class provides directory manipulation algorithms. More...

#include <utilities/directory_utilities.h>

List of all members.

Public Member Functions

virtual ~Directory ()

Static Public Member Functions

static void ForceCreateDirectory (const char *DirPath)
static void ForceCreateDirectory (const std::string &DirPath)
static bool DirectoryExists (const char *DirPath)
static bool DirectoryExists (const std::string &DirPath)

Detailed Description

Class provides directory manipulation algorithms.

Author:
Dodonov A.A.

Definition at line 49 of file directory_utilities.h.


Constructor & Destructor Documentation

nitro::Directory::~Directory (  )  [virtual]

Destructor (virtual).

Author:
Dodonov A.A.

Definition at line 113 of file directory_utilities.cpp.

        {
                try
                {
                }
                catch( ... )
                {
                }
        }


Member Function Documentation

bool nitro::Directory::DirectoryExists ( const char *  DirPath  )  [static]

Function validates if the record exists.

Parameters:
DirPath - Path to the directory.
Returns:
true if the directory exists, false otherwise.
Exceptions:
nitro::exception Throws exception of that type with the description of the error.
Author:
Dodonov A.A.

Definition at line 73 of file directory_utilities.cpp.

References nitro::FSPath::AddEndSlash(), and nitro::DirectoryAbstraction::FindFirst().

Referenced by DirectoryExists(), and ForceCreateDirectory().

        {
                try
                {
                        nitro::DirectoryAbstraction             Directory;
                        std::string                             TmpDirectoryPath( nitro::FSPath::AddEndSlash( std::string( DirPath ) ) );

                        if( Directory.FindFirst( TmpDirectoryPath.c_str() ) )
                        {
                                return( false );
                        }

                        return( true );
                }
                catch( nitro::exception e )
                {
                        return( false );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "bool Directory::DirectoryExists( const char * DirPath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

bool nitro::Directory::DirectoryExists ( const std::string &  DirPath  )  [static]

Function validates if the record exists.

Parameters:
DirPath - Path to the directory.
Returns:
true if the directory exists, false otherwise.
Exceptions:
nitro::exception Throws exception of that type with the description of the error.
Author:
Dodonov A.A.

Definition at line 97 of file directory_utilities.cpp.

References nitro::exception::code(), DirectoryExists(), and nitro::exception::what().

        {
                try
                {
                        return( DirectoryExists( DirPath.c_str() ) );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Directory::DirectoryExists( const std::string & DirPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Directory::DirectoryExists( const std::string & DirPath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::Directory::ForceCreateDirectory ( const char *  DirPath  )  [static]

Function creates directory. For example we are going to create directory e:/1/2 and directory e:/1 does not exists, so this function at first will create e:/1 and then will create e:/1/2

Parameters:
DirPath - Path to the creating directory.
Exceptions:
nitro::exception Throws exception of that type with the description of the error.
Author:
Dodonov A.A.

Definition at line 10 of file directory_utilities.cpp.

References nitro::exception::code(), nitro::DirectoryAbstraction::CreateDirectory(), nitro::FSPath::DeleteEndSlash(), DirectoryExists(), nitro::FSPath::ExtractFilePath(), and nitro::exception::what().

Referenced by ForceCreateDirectory(), nitro::File::ForceCreateFile(), and nitro::UnZIPAbstraction::UnZIPFile().

        {
                try
                {
                        char                    * SafePath;
                        SafePath = new char[ strlen( DirPath ) + 1 ];
                        // обрубаем концевой слэш если нужно
                        nitro::FSPath::DeleteEndSlash( DirPath , SafePath );

                        // произошла ошибка
                        // проверяем может быть директория создана раньше
                        if( DirectoryExists( ( const char * )SafePath ) )
                        {
                                // т.е. такая директория уже создана
                                // кстати тут обрабатывается такая ситуация - когда в функцию передан <drive_letter>:/
                                // тогда DirectoryExists вернет true для <drive_letter>:, т.к. она автоматом прибавляет / к пути
                                return;
                        }

                        // директория не была создана раньше следовательно идем выше по пути
                        char                    SubSafePath[ 4096 ];
                        if( std::string( nitro::FSPath::ExtractFilePath( SafePath , SubSafePath ) ) == SafePath )
                        {
                                // т.е. не удалось выделить имя файла
                                throw( nitro::exception( std::string( "An error occured while extracting file path from " ) + SafePath , 0 ) );
                        }
                        else
                        {
                                ForceCreateDirectory( ( const char * )SubSafePath );

                                DirectoryAbstraction::CreateDirectory( ( const char * )SafePath );

                                //директория создана
                        }

                        delete [] SafePath;
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "/* static */ void Directory::ForceCreateDirectory( const char * DirPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "/* static */ void Directory::ForceCreateDirectory( const char * DirPath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::Directory::ForceCreateDirectory ( const std::string &  DirPath  )  [static]

Function creates directory. For example we are going to create directory e:/1/2 and directory e:/1 does not exists, so this function at first will create e:/1 and then will create e:/1/2

Parameters:
DirPath - Path to the creating directory.
Exceptions:
nitro::exception - Throws exception of that type with the description of the error.
Author:
Dodonov A.A.

Definition at line 57 of file directory_utilities.cpp.

References nitro::exception::code(), ForceCreateDirectory(), and nitro::exception::what().

        {
                try
                {
                        ForceCreateDirectory( DirPath.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Directory::ForceCreateDirectory( const std::string & DirPath )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Directory::ForceCreateDirectory( const std::string & DirPath )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1