Basic Image AlgorithmS Library 2.8.0
Static Public Member Functions | Static Private Member Functions

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>

List of all members.

Static Public Member Functions

static std::string Basename (const std::string &fullname)
 Get file base name without path from given path and filename.
static int ChDir (const std::string &dir)
 Change current working directory.
static std::string CorrectSlashes (const std::string &thepath)
 Replace wrong slashes with respect to current operating system.
static int CreateDir (const std::string &subdir)
 Create directory (parent directory must exist).
static int CreateDirRecursive (const std::string &dir)
 Create directory recursively (if any parent directory does not exist it will be created).
static std::string CurrentDateTimeString ()
 Create a string containing date and time like 20060329_173054.
static std::string Directory (const std::string &fullname)
 Get directory from given path and filename.
static std::string DirectoryAndBasename (const std::string &fullname)
 Get path and file base name (without suffix) from given path and filename.
static std::string Extension (const std::string &fullname)
 Get file extension (without dot!) from given path and filename.
static int ExtractNumberFromRight (const std::string &inStr, int &number, int &posL, int &posR)
 Extract numeric value from string beginning from right, e.g.
static bool FileExists (const std::string &file)
 Check if the given file exists.
static std::string Filename (const std::string &fullname)
 Get file name (base name + suffix) without path from given path and filename.
static int FilenameExpansion (const std::string &in, std::string &out)
 Expand filename, e.g.
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.
static bool FileReadable (const std::string &filename)
 Checks if the given file exists and is readable on file system.
static std::string GetApplicationPath ()
 Return full path of current thread/application/module/exe/dll.
static std::string GetCwd ()
 Return current working directory as string.
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.
static bool IsAbsolute (const std::string &path)
 Determines if path is absolute (starting with "/") or local.
static std::string LeadingZeroString (const int &n, const unsigned int &digits=DEFAULT_LEADING_ZEROS)
 Create a string with leading zeroes from number.
static void LogCommandLine (int argc, char **argv, std::ostream &os)
 Write compilation time/date and all command line arguments to an output stream.
static void LogCommandLine (int argc, char **argv, const std::string &filename)
 Write compilation time/date and all command line arguments to a log file.
static std::string LowerCase (const std::string &input)
 Return lower case string of input.
static int RemoveDir (const std::string &subdir)
 Delete directory and all contents.
static bool RemoveFile (const std::string &filename)
 Removes the file with the given name.
static void SplitName (const std::string &fullname, std::string &dir, std::string &base, std::string &suffix)
 Split full path into:

  • directory
  • file base name
  • file suffix (including dot!)

static void SplitPath (const std::string &fullpath, std::vector< std::string > &result)
 Split full directory name into individual subdirectory names, e.g.
static std::string StripTerminatingSlash (const std::string &thepath)
 Remove a trailing slash from the path if there is one.
static std::string Suffix (const std::string &fullname)
 Get file suffix (including dot!) from given path and filename.
template<class T >
static std::string toString (const T thenumber, int numzeros=DEFAULT_LEADING_ZEROS)
 Converts number to string with leading zeros.
static std::string UpperCase (const std::string &input)
 Return upper case string of input.

Static Private Member Functions

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

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

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

Change current working directory.

static std::string BIAS::FileHandling::CorrectSlashes ( const std::string &  thepath) [inline, static]

Replace wrong slashes with respect to current operating system.

Definition at line 221 of file FileHandling.hh.

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

Create directory (parent directory must exist).

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

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

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

Create a string containing date and time like 20060329_173054.

Author:
koeser

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

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

Get directory from given path and filename.

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

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

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

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

static std::string BIAS::FileHandling::Extension ( const std::string &  fullname) [static]
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".

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

Check if the given file exists.

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

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

static 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

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

static 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
static bool BIAS::FileHandling::FileReadable ( const std::string &  filename) [static]

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

Examples:
ExampleImageWinApi.cpp.
static std::string BIAS::FileHandling::GetApplicationPath ( ) [static]

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

Author:
Jan Woetzel
static std::string BIAS::FileHandling::GetCwd ( ) [static]

Return current working directory as string.

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

static 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.

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

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

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

static std::string BIAS::FileHandling::LeadingZeroString ( const int &  n,
const unsigned int &  digits = DEFAULT_LEADING_ZEROS 
) [static]
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.

static 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.

static std::string BIAS::FileHandling::LowerCase ( const std::string &  input) [static]
static int BIAS::FileHandling::RemoveDir ( const std::string &  subdir) [static]

Delete directory and all contents.

static bool BIAS::FileHandling::RemoveFile ( const std::string &  filename) [inline, static]

Removes the file with the given name.

Just wraps C call.

Definition at line 80 of file FileHandling.hh.

static 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.

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

static 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!
static std::string BIAS::FileHandling::StripTerminatingSlash ( const std::string &  thepath) [inline, static]

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

Definition at line 203 of file FileHandling.hh.

static std::string BIAS::FileHandling::Suffix ( const std::string &  fullname) [static]
static char BIAS::FileHandling::ToLower_c ( char  c) [static, private]

Type correct helper wrapper for tolower, required for chars.

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

Type correct helper wrapper for toupper, required for chars.

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

Return upper case string of input.


The documentation for this class was generated from the following file:
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends