BASIS  version 1.2.3 (revision 2104)
Functions | Variables
path.h File Reference

Basic file path manipulation and related system functions. More...

#include <string>
#include <set>
+ Include dependency graph for path.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string sbia::basis::clean_path (const std::string &path)
 Clean path, i.e., remove occurences of "./", duplicate slashes,...
bool sbia::basis::clear_directory (const std::string &path)
 Remove files and directories from directory.
bool sbia::basis::exists (const std::string path)
 Test the existance of a file or directory.
std::string sbia::basis::get_executable_directory ()
 Get canonical path of directory containing executable file.
std::string sbia::basis::get_executable_name ()
 Get name of executable.
std::string sbia::basis::get_executable_path ()
 Get canonical path of executable file.
std::string sbia::basis::get_file_directory (const std::string &path)
 Get file directory.
std::string sbia::basis::get_file_name (const std::string &path)
 Get file name with extension.
std::string sbia::basis::get_file_name_extension (const std::string &path, const std::set< std::string > *exts=NULL)
 Get file name extension.
std::string sbia::basis::get_file_name_without_extension (const std::string &path, const std::set< std::string > *exts=NULL)
 Get file name without extension.
std::string sbia::basis::get_file_root (const std::string &path)
 Get file root.
std::string sbia::basis::get_real_path (const std::string &path)
 Get canonical file path.
std::string sbia::basis::get_working_directory ()
 Get absolute path of the (current) working directory.
bool sbia::basis::has_extension (const std::string &path, const std::set< std::string > *exts=NULL)
 Test whether a given path has an extension.
bool sbia::basis::is_absolute (const std::string &path)
 Test whether a given path is absolute.
bool sbia::basis::is_dir (const std::string path)
 Test whether a given path is the path of an existent directory.
bool sbia::basis::is_file (const std::string path)
 Test whether a given path is the path of an existent file.
bool sbia::basis::is_relative (const std::string &path)
 Test whether a given path is relative.
bool sbia::basis::is_symlink (const std::string &path)
 Whether a given path is a symbolic link.
bool sbia::basis::is_valid_path (const std::string &path, bool strict=true)
 Whether a given string is a valid path.
std::string sbia::basis::join_paths (const std::string &base, const std::string &path)
 Join two paths, e.g., base path and relative path.
bool sbia::basis::make_directory (const std::string &path, bool parent=true)
 Make directory optionally including parent directories.
bool sbia::basis::read_symlink (const std::string &link, std::string &value)
 Read value of symbolic link.
bool sbia::basis::remove_directory (const std::string &path, bool recursive=false)
 Remove directory.
void sbia::basis::split_path (const std::string &path, std::string *root, std::string *dir, std::string *fname, std::string *ext, const std::set< std::string > *exts=NULL)
 Split path into its components.
std::string sbia::basis::to_absolute_path (const std::string &path)
 Get absolute path given a relative path.
std::string sbia::basis::to_absolute_path (const std::string &base, const std::string &path)
 Get absolute path given a relative path and a base path.
std::string sbia::basis::to_native_path (const std::string &path)
 Convert path to native representation.
std::string sbia::basis::to_relative_path (const std::string &path)
 Get path relative to current working directory.
std::string sbia::basis::to_relative_path (const std::string &base, const std::string &path)
 Get path relative to given absolute path.
std::string sbia::basis::to_unix_path (const std::string &path, bool drive=false)
 Convert path to Unix representation.
std::string sbia::basis::to_windows_path (const std::string &path)
 Convert path to Windows representation.

Variables

const char sbia::basis::cPathSeparator = '/'
 Native path separator, i.e., either slash (/) or backslash (\).
const std::string sbia::basis::cPathSeparatorStr
 Native path separator as string, i.e., either slash (/) or backslash (\).

Detailed Description

Basic file path manipulation and related system functions.

The implementations provided by this module are related to the manipulation of file paths. These implementations are meant to be simple and therefore focus on non-multibyte path strings only.

Note that in order to improve portability and because of the main focus on Unix-based systems, slashes (/) are used as path separators. A function to convert a given path to its native representation is provided, however. Further, only relative paths and absolute paths which start with a slash (/) on Unix-based systems or a slash (/), backslash (\), or drive specification on Windows are supported. Hence, UNC paths, the inclusion of a hostname in the path,... are not supported. Also, masking of slashes or backslashes is not supported either. This is just a simple implementation that should work for most of the use cases in software written at SBIA. If not, please contact the maintainer of the BASIS package.

Copyright (c) 2011 University of Pennsylvania. All rights reserved.
See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.

Contact: SBIA Group <sbia-software at uphs.upenn.edu>

Definition in file path.h.