pdal::FileUtils
¶
-
namespace
pdal
::
FileUtils
¶ Functions
-
std::istream *
openFile
(std::string const &filename, bool asBinary = true)¶ Open an existing file for reading.
- Return
Pointer to opened stream.
- Parameters
filename
: Filename.asBinary
: Read as binary file (don’t convert /r/n to /n)
-
std::ostream *
createFile
(std::string const &filename, bool asBinary = true)¶ Create a file and open for writing.
- Return
Point to opened stream.
- Parameters
filename
: Filename.asBinary
: Write as binary file (don’t convert /n to /r/n)
-
bool
directoryExists
(const std::string &dirname)¶ Determine if a directory exists.
- Return
Whether a directory exists.
- Parameters
dirname
: Name of directory.
-
bool
createDirectory
(const std::string &dirname)¶ Create a directory.
- Return
Whether the directory was created.
- Parameters
dirname
: Directory name.
-
bool
createDirectories
(const std::string &path)¶ Create all directories in the provided path.
- Return
on failure
- Parameters
dirname
: Path name.
-
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.
- Return
List of entries in the directory.
- Parameters
dirname
: Name of directory to list.
-
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.
- Return
true
if successful,false
otherwise- Parameters
filename
: Name of file to delete.
-
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.
- Return
Whether the file exists.
- Parameters
Filename.
:
-
uintmax_t
fileSize
(const std::string &filename)¶ Get the size of a file.
- Return
Size of file.
- Parameters
filename
: Filename.
-
std::string
readFileIntoString
(const std::string &filename)¶ Read a file into a string.
- Return
File contents as a string
- Parameters
filename
: Filename.
-
std::string
getcwd
()¶ Get the current working directory with trailing separator.
- Return
The current working directory.
-
std::string
toCanonicalPath
(std::string filename)¶ Return the path with all “.”, “..” and symbolic links removed.
The file must exist.
- Return
Canonical version of provided filename, or empty string.
- Parameters
filename
: Name of file to convert to canonical path.
-
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.
- Return
Absolute version of provided filename.
- Parameters
filename
: Name of file to convert to absolute path.
-
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.
- Return
Absolute version of provided filename relative to base.
- Parameters
filename
: Name of file to convert to absolute path.base
: Base name to use.
-
std::string
getFilename
(const std::string &path)¶ Return the file component of the given path, e.g.
“d:/foo/bar/a.c” -> “a.c”
- Return
File part of path.
- Parameters
path
: Path from which to extract file component.
-
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/”
- Return
Directory part of path.
- Parameters
path
: Path from which to extract directory component.
-
std::string
stem
(const std::string &path)¶ Return the filename stripped of the extension.
. and .. are returned unchanged.
- Return
Stem of filename.
- Parameters
path
: File path from which to extract file stem.
-
bool
isDirectory
(const std::string &path)¶ Determine if path is a directory.
- Return
Whether the path represents a directory.
- Parameters
path
: Directory to check.
-
bool
isAbsolutePath
(const std::string &path)¶ Determine if the path is an absolute path.
- Return
Whether the path is absolute.
- Parameters
path
: Path to test.
-
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 (.).
- Return
Extension of filename.
- Parameters
path
: File path from which to extract extension.
-
std::vector<std::string>
glob
(std::string filespec)¶ Expand a filespec to a list of files.
- Return
List of files that correspond to provided file specification.
- Parameters
filespec
: File specification to expand.
-
MapContext
mapFile
(const std::string &filename, bool readOnly, size_t pos, size_t size)¶ Map a file to memory.
- Return
MapContext. addr() gets the mapped address. what() gets any error message. addr() returns nullptr on error.
- 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.
-
MapContext
unmapFile
(MapContext ctx)¶ Unmap a previously mapped file.
- Return
MapContext indicating current state of the file mapping.
- Parameters
ctx
: Previously returned MapContext
-
struct
MapContext
¶ - #include <FileUtils.hpp>
-
std::istream *