pdal::FileUtils
#
-
namespace FileUtils#
Functions
-
std::string toNative(const std::string &in)#
-
std::string fromNative(const std::string &in)#
-
std::istream *openFile(std::string const &filename, bool asBinary = true)#
Open an existing file for reading.
- Parameters:
filename – Filename.
asBinary – Read as binary file (don’t convert /r/n to /n)
- Returns:
Pointer to opened stream.
-
std::ostream *createFile(std::string const &filename, bool asBinary = true)#
Create/truncate a file and open for writing.
- Parameters:
filename – Filename.
asBinary – Write as binary file (don’t convert /n to /r/n)
- Returns:
Point to opened stream.
-
std::ostream *openExisting(std::string const &filename, bool asBinary = true)#
Open an existing file for write.
- Parameters:
filename – Filename.
asBinary – Write as binary file (don’t convert /n to /r/n)
- Returns:
Point to opened stream.
-
bool directoryExists(const std::string &dirname)#
Determine if a directory exists.
- Parameters:
dirname – Name of directory.
- Returns:
Whether a directory exists.
-
bool createDirectory(const std::string &dirname)#
Create a directory.
- Parameters:
dirname – Directory name.
- Returns:
Whether the directory was created.
-
bool createDirectories(const std::string &path)#
Create all directories in the provided path.
- Parameters:
dirname – Path name.
- Returns:
\false on failure
-
void deleteDirectory(const std::string &dirname)#
Delete a directory and its contents.
- Parameters:
dirname – Directory name.
-
std::vector<std::string> directoryList(const std::string &dirname)#
List the contents of a directory.
- Parameters:
dirname – Name of directory to list.
- Returns:
List of entries in the directory.
-
void closeFile(std::ostream *ofs)#
Close a file created with createFile.
- Parameters:
ofs – Pointer to stream to close.
-
void closeFile(std::istream *ifs)#
Close a file created with openFile.
- Parameters:
ifs – Pointer to stream to close.
-
bool deleteFile(const std::string &filename)#
Delete a file.
- Parameters:
filename – Name of file to delete.
- Returns:
true
if successful,false
otherwise
-
void renameFile(const std::string &dest, const std::string &src)#
Rename a file.
- Parameters:
dest – Desired filename.
src – Source filename.
-
bool fileExists(const std::string &filename)#
Determine if a file exists.
- Parameters:
Filename. –
- Returns:
Whether the file exists.
-
uintmax_t fileSize(const std::string &filename)#
Get the size of a file.
- Parameters:
filename – Filename.
- Returns:
0 on error or invalid file type.
- Returns:
Size of file.
-
std::string readFileIntoString(const std::string &filename)#
Read a file into a string.
- Parameters:
filename – Filename.
- Returns:
File contents as a string
-
std::string getcwd()#
Get the current working directory with trailing separator.
- Returns:
The current working directory.
-
std::string toCanonicalPath(std::string filename)#
Return the path with all “.”, “..” and symbolic links removed.
The file must exist.
- Parameters:
filename – Name of file to convert to canonical path.
- Returns:
Canonical version of provided filename, or empty string.
-
std::string toAbsolutePath(const std::string &filename)#
If the filename is an absolute path, just return it otherwise, make it absolute (relative to current working dir) and return it.
- Parameters:
filename – Name of file to convert to absolute path.
- Returns:
Absolute version of provided filename.
-
std::string toAbsolutePath(const std::string &filename, const std::string base)#
If the filename is an absolute path, just return it otherwise, make it absolute (relative to base dir) and return that.
- Parameters:
filename – Name of file to convert to absolute path.
base – Base name to use.
- Returns:
Absolute version of provided filename relative to base.
-
std::string getFilename(const std::string &path)#
Return the file component of the given path, e.g.
“d:/foo/bar/a.c” -> “a.c”
- Parameters:
path – Path from which to extract file component.
- Returns:
File part of path.
-
std::string getDirectory(const std::string &path)#
Return the directory component of the given path, e.g.
“d:/foo/bar/a.c” -> “d:/foo/bar/”
- Parameters:
path – Path from which to extract directory component.
- Returns:
Directory part of path.
-
std::string stem(const std::string &path)#
Return the filename stripped of the extension.
. and .. are returned unchanged.
- Parameters:
path – File path from which to extract file stem.
- Returns:
Stem of filename.
-
bool isDirectory(const std::string &path)#
Determine if path is a directory.
- Parameters:
path – Directory to check.
- Returns:
Whether the path represents a directory.
-
bool isAbsolutePath(const std::string &path)#
Determine if the path is an absolute path.
- Parameters:
path – Path to test.
- Returns:
Whether the path is absolute.
-
void fileTimes(const std::string &filename, struct tm *createTime, struct tm *modTime)#
Get the file creation and modification times.
- Parameters:
filename – Filename.
createTime – Pointer to creation time structure.
modTime – Pointer to modification time structure.
-
std::string extension(const std::string &path)#
Return the extension of the filename, including the separator (.).
- Parameters:
path – File path from which to extract extension.
- Returns:
Extension of filename.
-
std::vector<std::string> glob(std::string filespec)#
Expand a filespec to a list of files.
- Parameters:
filespec – File specification to expand.
- Returns:
List of files that correspond to provided file specification.
-
MapContext mapFile(const std::string &filename, bool readOnly = true, uintmax_t pos = 0, uintmax_t size = 0)#
Map a file to memory.
- Parameters:
filename – Filename to map.
readOnly – Must be true at this time.
pos – Starting position of file to map.
size – Number of bytes in file to map.
- Returns:
MapContext. addr() gets the mapped address. what() gets any error message. addr() returns nullptr on error.
-
MapContext unmapFile(MapContext ctx)#
Unmap a previously mapped file.
- Parameters:
ctx – Previously returned MapContext
- Returns:
MapContext indicating current state of the file mapping.
-
struct MapContext#
- #include <FileUtils.hpp>
-
std::string toNative(const std::string &in)#