Thea
Classes | Static Public Member Functions | List of all members
FileSystem Class Reference

Filesystem operations. More...

#include <FileSystem.hpp>

Classes

struct  Flags
 Miscellaneous flags (enum class). More...
 
struct  ObjectType
 Types of objects in the filesystem (enum class). More...
 

Static Public Member Functions

static bool copyFile (std::string const &from, std::string const &to)
 Make a copy of a file. More...
 
static bool createDirectory (std::string const &path)
 Create a directory, including all necessary parents (equivalent to "mkdir -p"). More...
 
static bool directoryExists (std::string const &path)
 Check if a directory exists, and is indeed a directory (and not for instance a file). More...
 
static bool exists (std::string const &path)
 Check if a file or directory exists. More...
 
static bool fileExists (std::string const &path)
 Check if a file exists, and is indeed a regular file (and not for instance a directory). More...
 
static int64 fileSize (std::string const &path)
 Get the length of a file in bytes. More...
 
static intx getDirectoryContents (std::string const &dir, Array< std::string > &objects, int types=-1, std::string const &patterns="", int flags=0)
 Get the objects (files, subdirectories etc) in a directory, optionally filtering objects by type and name. More...
 
static std::string readWholeFile (std::string const &path)
 Get the entire contents of a file as a string. More...
 
static bool readWholeFile (std::string const &path, std::string &ret)
 Get the entire contents of a file as a string. More...
 
static bool remove (std::string const &path, bool recursive=false)
 Remove a file, a symbolic link, or a directory. More...
 
static std::string resolve (std::string const &path)
 Resolve a relative path. More...
 

Detailed Description

Filesystem operations.

Unlike FilePath, these functions do actually access the filesystem.

Note
Returned paths are in native OS format (e.g. backslashes on Windows, forward slashes on Unix).

Definition at line 27 of file FileSystem.hpp.

Member Function Documentation

bool copyFile ( std::string const &  from,
std::string const &  to 
)
static

Make a copy of a file.

Fails, returning false, if the destination already exists.

Parameters
fromThe source path.
toThe destination path.
Returns
True if the file was successfully copied, else false.
Todo:
Document the behaviour properly for files/symlinks/directories, on different platforms.

Definition at line 230 of file FileSystem.cpp.

bool createDirectory ( std::string const &  path)
static

Create a directory, including all necessary parents (equivalent to "mkdir -p").

Returns
True if the directory already exists or was successfully created, false on error.

Definition at line 60 of file FileSystem.cpp.

bool directoryExists ( std::string const &  path)
static

Check if a directory exists, and is indeed a directory (and not for instance a file).

Definition at line 38 of file FileSystem.cpp.

bool exists ( std::string const &  path)
static

Check if a file or directory exists.

Definition at line 26 of file FileSystem.cpp.

bool fileExists ( std::string const &  path)
static

Check if a file exists, and is indeed a regular file (and not for instance a directory).

Definition at line 32 of file FileSystem.cpp.

int64 fileSize ( std::string const &  path)
static

Get the length of a file in bytes.

Returns a negative number on failure.

Definition at line 44 of file FileSystem.cpp.

intx getDirectoryContents ( std::string const &  dir,
Array< std::string > &  objects,
int  types = -1,
std::string const &  patterns = "",
int  flags = 0 
)
static

Get the objects (files, subdirectories etc) in a directory, optionally filtering objects by type and name.

Symbolic links are returned as symbolic links and are not dereferenced to the files or directories they point to.

Note
Subdirectories are not traversed recursively unless Flags::RECURSIVE is added to the flags argument.
Parameters
dirThe path to the directory.
objectsUsed to return the full paths of all retrieved objects in the directory. Prior contents are discarded.
typesA bitwise-OR of ObjectType flags (pass zero, negative or ObjectType::ALL to allow all types of objects).
patternsIf this string is non-empty, it is split into fields separated by spaces and each field interpreted as a shell wildcard pattern specified in the format of patternMatch(). The function will return only objects whose names (without path) match at least one of the patterns. E.g. patterns = "*.txt *.png" will return only files with names ending in .txt or .png.
flagsA bitwise OR of Flags values specifying additional options, e.g. recursive subdirectory traversal, case-insensitive pattern matching, or sorted output.
Returns
The number of objects found, equal to the size of objects. If the supplied path is not a directory, returns a negative value.

Definition at line 166 of file FileSystem.cpp.

static std::string readWholeFile ( std::string const &  path)
static

Get the entire contents of a file as a string.

Definition at line 84 of file FileSystem.hpp.

bool readWholeFile ( std::string const &  path,
std::string &  ret 
)
static

Get the entire contents of a file as a string.

Returns
True on success, false on error.

Definition at line 69 of file FileSystem.cpp.

bool remove ( std::string const &  path,
bool  recursive = false 
)
static

Remove a file, a symbolic link, or a directory.

If the path is a directory, the operation succeeds only if the directory is empty or if recursive is true.

Parameters
pathThe path to remove.
recursiveIf true, and if the path points to a directory, contents of the directory are recursively removed before the directory itself.
Returns
True if the object was successfully removed or did not exist in the first place, false on error (e.g. directory not empty (with recursive == false) or operation not permitted).

Definition at line 212 of file FileSystem.cpp.

std::string resolve ( std::string const &  path)
static

Resolve a relative path.

Definition at line 54 of file FileSystem.cpp.


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