Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
core_lib::file_utils Namespace Reference

The file_utils namespace. More...

Enumerations

enum  eCopyDirectoryOptions { eCopyDirectoryOptions::failIfTargetExists, eCopyDirectoryOptions::continueIfTargetExists }
 Copy directory options enumeration. More...
 

Functions

bool CORE_LIBRARY_DLL_SHARED_API FindFileRecursively (const std::wstring &dirPath, const std::wstring &fileName, std::wstring &pathFound, bool includeFileName=true)
 Find the common root path of 2 paths. More...
 
std::wstring CORE_LIBRARY_DLL_SHARED_API FindCommonRootPath (const std::wstring &path1, const std::wstring &path2)
 Find the common root path of 2 paths. More...
 
void CORE_LIBRARY_DLL_SHARED_API CopyDirectoryRecursively (const std::wstring &source, const std::wstring &target, eCopyDirectoryOptions options=eCopyDirectoryOptions::continueIfTargetExists)
 Recursively copy one directory and its contents to another location. More...
 
std::list< std::wstring > CORE_LIBRARY_DLL_SHARED_API ListDirectoryContents (const std::wstring &path, const std::wstring &extMatch=L"")
 List of regular files in the specified directory. More...
 
std::list< std::wstring > CORE_LIBRARY_DLL_SHARED_API ListSubDirectories (const std::wstring &path)
 List of immediate sub-directories in the specified directory. More...
 

Detailed Description

The file_utils namespace.

Enumeration Type Documentation

◆ eCopyDirectoryOptions

Copy directory options enumeration.

Enumerator
failIfTargetExists 

Do not continue copying if target directory exists.

continueIfTargetExists 

Continue copying even if target directory exists.

Function Documentation

◆ CopyDirectoryRecursively()

void core_lib::file_utils::CopyDirectoryRecursively ( const std::wstring &  source,
const std::wstring &  target,
eCopyDirectoryOptions  options = eCopyDirectoryOptions::continueIfTargetExists 
)

Recursively copy one directory and its contents to another location.

Parameters
[in]source- Source path from where we will copy data.
[in]target- Target path to where we will place the copied data.
[in]options- Control how to handle exsiting target locations.

Based on an example given in Learning Boost C++ Libraries by Arindam Mukherjee.

Preconditions that are enforced by this function are:

  1. The source path must be a directory.
  2. The target path must be a directory and may or may not exist.
  3. The parent of the target path must be a directory.
  4. The target path must not be a subdirectory of the source path.

Throws std::runtime_error if an error occurs. If target folder already exists then the source is copied into a folder within the target folder with the same name as the srouce folder.

◆ FindCommonRootPath()

std::wstring core_lib::file_utils::FindCommonRootPath ( const std::wstring &  path1,
const std::wstring &  path2 
)

Find the common root path of 2 paths.

Parameters
[in]path1- First path.
[in]path2- Second path.

Based on an example given in Learning Boost C++ Libraries by Arindam Mukherjee.

◆ FindFileRecursively()

bool core_lib::file_utils::FindFileRecursively ( const std::wstring &  dirPath,
const std::wstring &  fileName,
std::wstring &  pathFound,
bool  includeFileName = true 
)

Find the common root path of 2 paths.

Parameters
[in]dirPath- Directory to search recusively.
[in]fileName- Name of file to search for.
[out]pathFound- Full path to the file.
[in]includeFileName- Flag to indicate if pathFound should include name of file.
Returns
True if found, false otherwise.

◆ ListDirectoryContents()

std::list< std::wstring > core_lib::file_utils::ListDirectoryContents ( const std::wstring &  path,
const std::wstring &  extMatch = L"" 
)

List of regular files in the specified directory.

Parameters
[in]path- Directory path.
[in]extMatch- (Optional) If specified then should be the file extension to filter by.
Returns
List of files in the directory.

Throws boost::filesystem_error if a problem occurs.

◆ ListSubDirectories()

std::list< std::wstring > core_lib::file_utils::ListSubDirectories ( const std::wstring &  path)

List of immediate sub-directories in the specified directory.

Parameters
[in]path- Directory path.
Returns
List of sub-directories in the directory.

Throws boost::filesystem_error if a problem occurs.