Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Static Public Member Functions | Static Private Member Functions | List of all members
BIAS::FileHandling Class Reference

Functions to create, check and delete files and to handle file names, such as splitting into directory, filename and suffix. More...

#include <Base/Common/FileHandling.hh>

Static Public Member Functions

static std::string Basename (const std::string &fullname)
 Get file base name without path from given path and filename. More...
 
static int ChDir (const std::string &dir)
 Change current working directory. More...
 
static bool CopyFileTo (const std::string &oldFilename, const std::string &newFilename)
 Copies the file with the given name. More...
 
static std::string CorrectSlashes (const std::string &thepath)
 Replace wrong slashes with respect to current operating system. More...
 
static int CreateDir (const std::string &subdir)
 Create directory (parent directory must exist). More...
 
static int CreateDirRecursive (const std::string &dir)
 Create directory recursively (if any parent directory does not exist it will be created). More...
 
static std::string CurrentDateTimeString ()
 Create a string containing date and time like 20060329_173054. More...
 
static std::string Directory (const std::string &fullname)
 Get directory from given path and filename. More...
 
static std::string DirectoryAndBasename (const std::string &fullname)
 Get path and file base name (without suffix) from given path and filename. More...
 
static std::string Extension (const std::string &fullname)
 Get file extension (without dot!) from given path and filename. More...
 
static int ExtractNumberFromRight (const std::string &inStr, int &number, int &posL, int &posR)
 Extract numeric value from string beginning from right, e.g. More...
 
static bool FileExists (const std::string &file)
 Check if the given file exists. More...
 
static std::string Filename (const std::string &fullname)
 Get file name (base name + suffix) without path from given path and filename. More...
 
static int FilenameExpansion (const std::string &in, std::string &out)
 Expand filename, e.g. More...
 
static int FilenameSequence (const std::string &refFileName, std::string &resultFilename, const int &offsetFromRef, const unsigned int &stepsize=1)
 Construct sequential filename from a given filename by manipulating the number within base part of. More...
 
static bool FileReadable (const std::string &filename)
 Checks if the given file exists and is readable on file system. More...
 
static std::string GetApplicationPath ()
 Return full path of current thread/application/module/exe/dll. More...
 
static std::string GetCwd ()
 Return current working directory as string. More...
 
static int GetDirectoryContent (const std::string &Dir, const std::string &prefix, const std::string &suffix, std::vector< std::string > &content, const bool GetFullPath=false)
 Read all files in. More...
 
static bool IsAbsolute (const std::string &path)
 Determines if path is absolute (starting with "/") or local. More...
 
static std::string LeadingZeroString (const int &n, const unsigned int &digits=DEFAULT_LEADING_ZEROS)
 Create a string with leading zeroes from number. More...
 
static void LogCommandLine (int argc, char **argv, std::ostream &os)
 Write compilation time/date and all command line arguments to an output stream. More...
 
static void LogCommandLine (int argc, char **argv, const std::string &filename)
 Write compilation time/date and all command line arguments to a log file. More...
 
static std::string LowerCase (const std::string &input)
 Return lower case string of input. More...
 
static bool MoveOrRenameFile (const std::string &oldFilename, const std::string &newFilename)
 Renames or moves the file with the given name. More...
 
static int RemoveDir (const std::string &subdir)
 Delete directory and all contents. More...
 
static bool RemoveFile (const std::string &filename)
 Removes the file with the given name. More...
 
static void SplitName (const std::string &fullname, std::string &dir, std::string &base, std::string &suffix)
 Split full path into: More...
 
static void SplitPath (const std::string &fullpath, std::vector< std::string > &result)
 Split full directory name into individual subdirectory names, e.g. More...
 
static std::string StripTerminatingSlash (const std::string &thepath)
 Remove a trailing slash from the path if there is one. More...
 
static std::string Suffix (const std::string &fullname)
 Get file suffix (including dot!) from given path and filename. More...
 
template<class T >
static std::string toString (const T thenumber, int numzeros=DEFAULT_LEADING_ZEROS)
 Converts number to string with leading zeros. More...
 
static std::string UpperCase (const std::string &input)
 Return upper case string of input. More...
 

Static Private Member Functions

static char ToLower_c (char c)
 Type correct helper wrapper for tolower, required for chars. More...
 
static char ToUpper_c (char c)
 Type correct helper wrapper for toupper, required for chars. More...
 

Detailed Description

Functions to create, check and delete files and to handle file names, such as splitting into directory, filename and suffix.

Author
BIAS
Todo:
Correct handling of Win32 SAMBA paths including \machine...

Definition at line 47 of file FileHandling.hh.

Member Function Documentation

std::string BIAS::FileHandling::Basename ( const std::string &  fullname)
static
int BIAS::FileHandling::ChDir ( const std::string &  dir)
static

Change current working directory.

Definition at line 629 of file FileHandling.cpp.

bool BIAS::FileHandling::CopyFileTo ( const std::string &  oldFilename,
const std::string &  newFilename 
)
static

Copies the file with the given name.

Definition at line 226 of file FileHandling.cpp.

static std::string BIAS::FileHandling::CorrectSlashes ( const std::string &  thepath)
inlinestatic

Replace wrong slashes with respect to current operating system.

Definition at line 233 of file FileHandling.hh.

int BIAS::FileHandling::CreateDir ( const std::string &  subdir)
static

Create directory (parent directory must exist).

Definition at line 86 of file FileHandling.cpp.

int BIAS::FileHandling::CreateDirRecursive ( const std::string &  dir)
static

Create directory recursively (if any parent directory does not exist it will be created).

Definition at line 104 of file FileHandling.cpp.

std::string BIAS::FileHandling::CurrentDateTimeString ( )
static

Create a string containing date and time like 20060329_173054.

Author
koeser

Definition at line 449 of file FileHandling.cpp.

Referenced by BIAS::LDA::ComputeReductionMatrix().

std::string BIAS::FileHandling::Directory ( const std::string &  fullname)
static

Get directory from given path and filename.

Definition at line 307 of file FileHandling.cpp.

Referenced by BIAS::BVWXMainFrame::OnSaveAs(), BIAS::BVWXMainFrame::OnSaveAsMovie(), and BIAS::BVWXMainFrame::OnSaveCurrent().

std::string BIAS::FileHandling::DirectoryAndBasename ( const std::string &  fullname)
static

Get path and file base name (without suffix) from given path and filename.

Definition at line 351 of file FileHandling.cpp.

Referenced by BIAS::ImageIO::ExtensionName().

std::string BIAS::FileHandling::Extension ( const std::string &  fullname)
static
int BIAS::FileHandling::ExtractNumberFromRight ( const std::string &  inStr,
int &  number,
int &  posL,
int &  posR 
)
static

Extract numeric value from string beginning from right, e.g.

"blah042foo.txt" –> return 42 and positions of "0" and "2".

Definition at line 469 of file FileHandling.cpp.

bool BIAS::FileHandling::FileExists ( const std::string &  file)
static

Check if the given file exists.

Definition at line 138 of file FileHandling.cpp.

std::string BIAS::FileHandling::Filename ( const std::string &  fullname)
static

Get file name (base name + suffix) without path from given path and filename.

Definition at line 344 of file FileHandling.cpp.

int BIAS::FileHandling::FilenameExpansion ( const std::string &  in,
std::string &  out 
)
static

Expand filename, e.g.

tilde to home expands "~" to $HOME if set and $USERPROFILE otherwise.

Author
Jan Woetzel

Definition at line 561 of file FileHandling.cpp.

Referenced by BIAS::ImageIO::Load(), BIAS::XMLIO::read(), BIAS::ImageIO::Save(), and BIAS::XMLIO::write().

int BIAS::FileHandling::FilenameSequence ( const std::string &  refFileName,
std::string &  resultFilename,
const int &  offsetFromRef,
const unsigned int &  stepsize = 1 
)
static

Construct sequential filename from a given filename by manipulating the number within base part of.

Parameters
refFilenameof an image sequence given a reference filename and an offset. The number of leading zeroes is kept but digits may be added if required.
offsetFromRefNumber of frames forward or backward from ref. image
stepsizeNumber of increment/decrement per offset

Example: C:/foo/image00100bar.jpg ref=100, offset=2, stepsize=7 –> 114 resultFilename –> C:/foo/image00114bar.jpg or: foo9 -> foo10 foo009 -> foo010

Returns
0 for success, !=0 for failure.
Author
Jan Woetzel

Definition at line 528 of file FileHandling.cpp.

bool BIAS::FileHandling::FileReadable ( const std::string &  filename)
static

Checks if the given file exists and is readable on file system.

Examples:
ExampleImageWinApi.cpp.

Definition at line 217 of file FileHandling.cpp.

std::string BIAS::FileHandling::GetApplicationPath ( )
static

Return full path of current thread/application/module/exe/dll.

Author
Jan Woetzel

Definition at line 638 of file FileHandling.cpp.

std::string BIAS::FileHandling::GetCwd ( )
static

Return current working directory as string.

Definition at line 599 of file FileHandling.cpp.

Referenced by BIAS::ImageIO::Load(), BIAS::Projection::Load(), and BIAS::ProjectionParametersIO::ReadRigData().

int BIAS::FileHandling::GetDirectoryContent ( const std::string &  Dir,
const std::string &  prefix,
const std::string &  suffix,
std::vector< std::string > &  content,
const bool  GetFullPath = false 
)
static

Read all files in.

Parameters
Dir,matchagainst
suffixand
prefixand put into
content.If you want to use the full path, set
GetFullPath=true,otherwiseonly the file name is used.

Definition at line 147 of file FileHandling.cpp.

Referenced by BIAS::VideoSource_V4L::GetAllDevices().

bool FileHandling::IsAbsolute ( const std::string &  path)
static

Determines if path is absolute (starting with "/") or local.

Definition at line 654 of file FileHandling.cpp.

std::string BIAS::FileHandling::LeadingZeroString ( const int &  n,
const unsigned int &  digits = DEFAULT_LEADING_ZEROS 
)
static
void BIAS::FileHandling::LogCommandLine ( int  argc,
char **  argv,
std::ostream &  os 
)
static

Write compilation time/date and all command line arguments to an output stream.

Definition at line 392 of file FileHandling.cpp.

void BIAS::FileHandling::LogCommandLine ( int  argc,
char **  argv,
const std::string &  filename 
)
static

Write compilation time/date and all command line arguments to a log file.

Definition at line 405 of file FileHandling.cpp.

std::string BIAS::FileHandling::LowerCase ( const std::string &  input)
static
static bool BIAS::FileHandling::MoveOrRenameFile ( const std::string &  oldFilename,
const std::string &  newFilename 
)
inlinestatic

Renames or moves the file with the given name.

Just wraps C call.

Definition at line 87 of file FileHandling.hh.

int BIAS::FileHandling::RemoveDir ( const std::string &  subdir)
static

Delete directory and all contents.

Definition at line 69 of file FileHandling.cpp.

static bool BIAS::FileHandling::RemoveFile ( const std::string &  filename)
inlinestatic

Removes the file with the given name.

Just wraps C call.

Definition at line 80 of file FileHandling.hh.

void BIAS::FileHandling::SplitName ( const std::string &  fullname,
std::string &  dir,
std::string &  base,
std::string &  suffix 
)
static

Split full path into:

   - directory
   - file base name
   - file suffix (including dot!)
Todo:
Extract machine name or IP for SMB network shares for WIN32, e.g. \machine, and fix backslashes on WIN32. Fix also to make \, \ and / work on directories!
Author
Jan Woetzel
Examples:
ExampleHistogramEqualization.cpp.

Definition at line 243 of file FileHandling.cpp.

Referenced by BIAS::ScenePlainOpenSceneGraph::AppendSubTreeFromFile(), BIAS::SceneOpenSceneGraph::AppendSubTreeFromFile(), BIAS::ThreeDOutOpenSceneGraph::GenerateFilename_(), BIAS::SceneOpenSceneGraph::Load(), BIAS::ThreeDOutOpenSceneGraph::OpenSceneGraphOut(), BIAS::SceneOpenSceneGraph::Save(), and BIAS::SceneOpenSceneGraph::SaveSubTree().

void BIAS::FileHandling::SplitPath ( const std::string &  fullpath,
std::vector< std::string > &  result 
)
static

Split full directory name into individual subdirectory names, e.g.

/home/user/data -> ["home", "user", "data"].

Attention
If a file name is given in
Parameters
fullpath,itwill be returned as the last element of
result!

Definition at line 369 of file FileHandling.cpp.

static std::string BIAS::FileHandling::StripTerminatingSlash ( const std::string &  thepath)
inlinestatic

Remove a trailing slash from the path if there is one.

Definition at line 215 of file FileHandling.hh.

std::string BIAS::FileHandling::Suffix ( const std::string &  fullname)
static
char BIAS::FileHandling::ToLower_c ( char  c)
staticprivate

Type correct helper wrapper for tolower, required for chars.

Definition at line 425 of file FileHandling.cpp.

template<class T >
static std::string BIAS::FileHandling::toString ( const T  thenumber,
int  numzeros = DEFAULT_LEADING_ZEROS 
)
inlinestatic
char BIAS::FileHandling::ToUpper_c ( char  c)
staticprivate

Type correct helper wrapper for toupper, required for chars.

Definition at line 429 of file FileHandling.cpp.

std::string BIAS::FileHandling::UpperCase ( const std::string &  input)
static

Return upper case string of input.

Definition at line 441 of file FileHandling.cpp.


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