ccgl::utils_filesystem Namespace Reference

File Input and output related functions. More...

Functions

bool FileExists (string const &filename)
 Return a flag indicating if the given file exists. More...
 
bool FilesExist (vector< string > &filenames)
 Return a flag indicating if given files exist. More...
 
bool PathExists (string const &path)
 Return a flag indicating if the given path (directory or file) exists. More...
 
int DeleteExistedFile (const string &filepath)
 Delete the given file if existed. More...
 
int FindFiles (const char *lp_path, const char *expression, vector< string > &vec_files)
 Find files in given paths. More...
 
bool DirectoryExists (const string &dirpath)
 Check the given directory path (not regular file!) is exists or not.
 
bool MakeDirectory (const string &dirpath)
 Make directory if not exists.
 
bool CleanDirectory (const string &dirpath)
 Clean a directory if exists, otherwise create it. More...
 
bool DeleteDirectory (const string &dirpath, bool del_subdirs=true)
 Delete a directory if exists. More...
 
string GetAppPath ()
 Get the root path of the current executable file. More...
 
string GetAbsolutePath (string const &full_filename)
 Return the absolute file path from a given file path. More...
 
string GetCoreFileName (string const &full_filename)
 Return the file name from a given file's path. More...
 
string GetSuffix (string const &full_filename)
 Return the suffix of a given file's path without dot, e.g., "tif", "asc". More...
 
string ReplaceSuffix (string const &full_filename, string const &new_suffix)
 Replace the suffix by a given suffix. More...
 
string AppendCoreFileName (string const &full_filename, string const &endstr, char deli='_')
 Append a given string to the core filename. More...
 
string AppendCoreFileName (string const &full_filename, vint endint, char deli='_')
 Append a given integer to the core filename.
 
string PrefixCoreFileName (string const &full_filename, string const &prestr, char deli='_')
 Add a prefix to the core filename. More...
 
string PrefixCoreFileName (string const &full_filename, vint preint, char deli='_')
 Add a prefix to the core filename.
 
string GetPathFromFullName (string const &full_filename)
 Get Path From full file path string. More...
 
string ConcatFullName (string const &fdir, string const &corename, string const &suffix=std::string())
 Concatenate directory, core file name, and suffix.
 
bool LoadPlainTextFile (const string &filepath, vector< string > &content_strs)
 Load short plain text file as string vector, ignore comments begin with '#' and empty lines. More...
 

Detailed Description

File Input and output related functions.

Function Documentation

◆ AppendCoreFileName()

string ccgl::utils_filesystem::AppendCoreFileName ( string const &  full_filename,
string const &  endstr,
char  deli = '_' 
)

Append a given string to the core filename.

Parameters
[in]full_filenameFull file path
[in]endstrEnd string
[in]deli(Optional) Delimiter
Returns
new full_filename

◆ CleanDirectory()

bool ccgl::utils_filesystem::CleanDirectory ( const string &  dirpath)

Clean a directory if exists, otherwise create it.

empty the directory

◆ DeleteDirectory()

bool ccgl::utils_filesystem::DeleteDirectory ( const string &  dirpath,
bool  del_subdirs = true 
)

◆ DeleteExistedFile()

int ccgl::utils_filesystem::DeleteExistedFile ( const string &  filepath)

Delete the given file if existed.

Parameters
[in]filepathstring File path, full path or relative path
Returns
0 if deleted successful, else return nonzero value, e.g. -1.

◆ FileExists()

bool ccgl::utils_filesystem::FileExists ( string const &  filename)

Return a flag indicating if the given file exists.

Parameters
[in]filenameString path of file
Returns
True if Exists, and false if not.

◆ FilesExist()

bool ccgl::utils_filesystem::FilesExist ( vector< string > &  filenames)

Return a flag indicating if given files exist.

Parameters
[in]filenamesVector of full file paths
Returns
True if all existed, else false

◆ FindFiles()

int ccgl::utils_filesystem::FindFiles ( const char *  lp_path,
const char *  expression,
vector< string > &  vec_files 
)

Find files in given paths.

Parameters
[in]lp_pathDirectory path
[in]expressionWildcard characters, e.g., "*.*" means any filename with any suffix
[out]vec_filesVector of full file paths
Returns
0 means success

◆ GetAbsolutePath()

string ccgl::utils_filesystem::GetAbsolutePath ( string const &  full_filename)

Return the absolute file path from a given file path.

Parameters
[in]full_filenameFull file path
See also
GetPathFromFullName

◆ GetAppPath()

string ccgl::utils_filesystem::GetAppPath ( )

Get the root path of the current executable file.

Returns
string root path

◆ GetCoreFileName()

string ccgl::utils_filesystem::GetCoreFileName ( string const &  full_filename)

Return the file name from a given file's path.

Parameters
[in]full_filenameFull file path
See also
GetPathFromFullName

◆ GetPathFromFullName()

string ccgl::utils_filesystem::GetPathFromFullName ( string const &  full_filename)

Get Path From full file path string.

Parameters
[in]full_filenameFull file path
See also
GetCoreFileName

◆ GetSuffix()

string ccgl::utils_filesystem::GetSuffix ( string const &  full_filename)

Return the suffix of a given file's path without dot, e.g., "tif", "asc".

Parameters
[in]full_filenameFull file path
See also
GetPathFromFullName

◆ LoadPlainTextFile()

bool ccgl::utils_filesystem::LoadPlainTextFile ( const string &  filepath,
vector< string > &  content_strs 
)

Load short plain text file as string vector, ignore comments begin with '#' and empty lines.

Parameters
[in]filepathPlain text file path
[out]content_strsEach line without CRLF or LF stored in vector
Returns
True when read successfully, and false with empty content_strs when failed

◆ PathExists()

bool ccgl::utils_filesystem::PathExists ( string const &  path)

Return a flag indicating if the given path (directory or file) exists.

Parameters
[in]pathString path
Returns
True if Exists, and false if not.

◆ PrefixCoreFileName()

string ccgl::utils_filesystem::PrefixCoreFileName ( string const &  full_filename,
string const &  prestr,
char  deli = '_' 
)

Add a prefix to the core filename.

Parameters
[in]full_filenameFull file path
[in]prestrStart string
[in]deli(Optional) Delimiter
Returns
new full_filename

◆ ReplaceSuffix()

string ccgl::utils_filesystem::ReplaceSuffix ( string const &  full_filename,
string const &  new_suffix 
)

Replace the suffix by a given suffix.

Parameters
[in]full_filenameFull file path
[in]new_suffixNew suffix without dot, e.g., "tif", "asc"