A library for working with phylogenetic and population genetic data.
v0.27.0
fs.cpp File Reference

Detailed Description

Implementation of file system functions.

Definition in file fs.cpp.

#include "genesis/utils/core/fs.hpp"
#include <cassert>
#include <cctype>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <fstream>
#include <functional>
#include <limits.h>
#include <regex>
#include <set>
#include <sstream>
#include <stdexcept>
#include <stdlib.h>
#include <streambuf>
#include <sys/stat.h>
#include <unistd.h>
#include <utility>
#include "genesis/utils/core/algorithm.hpp"
#include "genesis/utils/io/gzip.hpp"
#include "genesis/utils/io/gzip_stream.hpp"
#include "genesis/utils/io/input_source.hpp"
#include "genesis/utils/io/input_stream.hpp"
#include "genesis/utils/io/output_stream.hpp"
#include "genesis/utils/io/scanner.hpp"
#include "genesis/utils/text/string.hpp"

Go to the source code of this file.

Namespaces

 genesis
 Container namespace for all symbols of genesis in order to keep them separate when used as a library.
 
 genesis::utils
 

Functions

static void build_path_base_swap_ (std::string &path, const std::string &newbase)
 
static std::string chdir_getcwd_ (std::string const &dir)
 
std::string current_path ()
 Return the current (working) directory, simiar to getcwd(). More...
 
static std::string current_path_getcwd_ ()
 
static std::string current_path_unix_ ()
 
void dir_create (std::string const &path, bool with_parents=true)
 Create a directory. More...
 
bool dir_exists (std::string const &dir)
 Return true iff the directory exists. More...
 
std::vector< std::string > dir_list_contents (std::string const &dir, bool full_path=false, std::string const &regex="")
 Get a list of files and directories in a directory. More...
 
static std::vector< std::string > dir_list_contents_ (std::string const &dir, bool full_path, std::string const &regex, std::function< bool(std::string const &)> condition)
 
std::vector< std::string > dir_list_directories (std::string const &dir, bool full_path=false, std::string const &regex="")
 Get a list of directories in a directory. More...
 
std::vector< std::string > dir_list_files (std::string const &dir, bool full_path=false, std::string const &regex="")
 Get a list of files in a directory. More...
 
std::string dir_normalize_path (std::string const &path)
 Normalize a dir name, i.e., make sure that the given path ends with exaclty one slash. More...
 
void file_append (std::string const &content, std::string const &filename, bool create_dirs=true)
 Append the content of a string to a file. More...
 
std::string file_basename (std::string const &filename)
 Remove directory name from file name if present. More...
 
std::string file_basename (std::string const &filename, std::vector< std::string > const &remove_extensions)
 Remove the directory name from a file name if present, and remove a list of given extensions. More...
 
bool file_exists (std::string const &filename)
 Return true iff the file exists. More...
 
std::string file_extension (std::string const &filename)
 Return the extension name of a file. More...
 
std::string file_filename (std::string const &filename)
 Remove extension if present. More...
 
std::unordered_map< std::string, std::string > file_info (std::string const &filename)
 Return information about a file. More...
 
std::string file_path (std::string const &filename)
 Return the path leading to a file. More...
 
std::string file_read (std::string const &filename, bool detect_compression=true)
 Return the contents of a file as a string. More...
 
std::vector< std::string > file_read_lines (std::string const &filename, bool detect_compression=true)
 Return the contents of a file as a vector of strings, one entry for each line. More...
 
size_t file_size (std::string const &filename)
 Return the size of a file. More...
 
void file_write (std::string const &content, std::string const &filename, bool create_dirs=true)
 Write the content of a string to a file. More...
 
bool is_dir (std::string const &path)
 Return true iff the provided path is a directory. More...
 
bool is_file (std::string const &path)
 Return true iff the provided path is a file. More...
 
bool is_valid_filename (std::string const &filename)
 Check whether a file name is valid. More...
 
bool path_exists (std::string const &path)
 Return whether a path exists, i.e., is a file or directory. More...
 
static bool readlink_internal_ (const std::string &path, std::string &buffer, ssize_t length)
 
std::string real_path (std::string const &path, bool resolve_link=true)
 Return the real path of a file or directory, similar to realpath(). More...
 
static std::string real_path_realpath_ (std::string const &path, bool resolve_link)
 
static std::string real_path_unix_ (std::string const &path, bool resolve_link)
 
static std::string realpath_file_ (const std::string &path)
 
static void relative_dir_base_split_ (std::string const &path, std::string &dir, std::string &base)
 
std::string sanitize_filename (std::string const &filename)
 Remove or replace all invalid parts of a filename. More...
 
static bool symlink_resolve_ (const std::string &start, std::string &end)