mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
|
Various file system utilities
Files | |
file | fileUtils.hpp |
Declarations of utilities for working with files. | |
file | fileUtils.cpp |
Definitions of utilities for working with files. | |
Functions | |
int | mx::ioutils::createDirectories (const std::string &path) |
Create a directory or directories. More... | |
std::string | mx::ioutils::pathStem (const std::string &fname) |
Get the stem of the filename. More... | |
std::string | mx::ioutils::pathFilename (const std::string &fname) |
Get the base filename. More... | |
std::string | mx::ioutils::parentPath (const std::string &fname) |
Get the parent path from a filename. More... | |
std::vector< std::string > | mx::ioutils::getFileNames (const std::string &directory, const std::string &prefix, const std::string &substr, const std::string &extension) |
Get a list of file names from the specified directory, specifying a prefix, a substring to match, and an extension. More... | |
std::vector< std::string > | mx::ioutils::getFileNames (const std::string &directory, const std::string &extension) |
Get a list of file names from the specified directory, specifying the extension. More... | |
std::vector< std::string > | mx::ioutils::getFileNames (const std::string &directory) |
Get a list of file names from the specified directory. More... | |
std::string | mx::ioutils::fileNamePrependAppend (const std::string &fname, const std::string &prepend, const std::string &append) |
Prepend and/or append strings to a file name, leaving the directory and extension unaltered. More... | |
std::string | mx::ioutils::fileNameAppend (const std::string &fname, const std::string &append) |
Append a string to a file name, leaving the directory and extension unaltered. More... | |
std::string | mx::ioutils::fileNamePrepend (const std::string &fname, const std::string &prepend) |
Prepend strings to a file name, leaving the directory and extension unaltered. More... | |
std::string | mx::ioutils::getSequentialFilename (const std::string &basename, const std::string &extension="", const int startat=0, int ndigit=4) |
Get the next file in a numbered sequence. More... | |
off_t | mx::ioutils::fileSize (int fd) |
Get the size in bytes of a file. More... | |
off_t | mx::ioutils::fileSize (FILE *f) |
Get the size in bytes of a file pointed to by a FILE pointer. More... | |
int mx::ioutils::createDirectories | ( | const std::string & | path | ) |
Create a directory or directories.
This will create any directories in path that don't exist. It silently ignores already existing directories.
[in] | path | the path of the directory(ies)to create |
Definition at line 52 of file fileUtils.cpp.
Referenced by mx::AO::path::dm::basisRoot(), mx::AO::path::dm::M2c(), mx::AO::path::dm::projectedModes(), mx::AO::path::basis::root(), mx::AO::path::dm::root(), mx::AO::path::pupil::root(), mx::AO::path::sys::root(), mx::AO::path::sys::cal::root(), and mx::AO::path::sys::cal::sysResp().
std::string mx::ioutils::fileNameAppend | ( | const std::string & | fname, |
const std::string & | append | ||
) |
Append a string to a file name, leaving the directory and extension unaltered.
[in] | fname | the original file name, possibly including a directory and extension |
[in] | append | is the string to insert at the end of the file name, before the extension |
Definition at line 199 of file fileUtils.cpp.
References mx::ioutils::fileNamePrependAppend().
std::string mx::ioutils::fileNamePrepend | ( | const std::string & | fname, |
const std::string & | prepend | ||
) |
Prepend strings to a file name, leaving the directory and extension unaltered.
[in] | fname | the original file name, possibly including a directory and extension |
[in] | prepend | is the string to insert at the beginning of the file name after the path |
Definition at line 206 of file fileUtils.cpp.
References mx::ioutils::fileNamePrependAppend().
std::string mx::ioutils::fileNamePrependAppend | ( | const std::string & | fname, |
const std::string & | prepend, | ||
const std::string & | append | ||
) |
Prepend and/or append strings to a file name, leaving the directory and extension unaltered.
[in] | fname | the original file name, possibly including a directory and extension |
[in] | prepend | is the string to insert at the beginning of the file name after the path |
[in] | append | is the string to insert at the end of the file name, before the extension |
Definition at line 181 of file fileUtils.cpp.
Referenced by mx::ioutils::fileNameAppend(), and mx::ioutils::fileNamePrepend().
off_t mx::ioutils::fileSize | ( | FILE * | f | ) |
Get the size in bytes of a file pointed to by a FILE pointer.
Uses fileno to get the associated descriptor, then uses fstat.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | f | an open file |
Definition at line 271 of file fileUtils.cpp.
References mx::ioutils::fileSize().
off_t mx::ioutils::fileSize | ( | int | fd | ) |
Get the size in bytes of a file.
Uses fstat.
[in] | fd | an open file descriptor |
Definition at line 253 of file fileUtils.cpp.
Referenced by mx::ioutils::fileSize().
std::vector< std::string > mx::ioutils::getFileNames | ( | const std::string & | directory | ) |
Get a list of file names from the specified directory.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | directory | the path to the directory to search. Can not be empty. |
Definition at line 175 of file fileUtils.cpp.
References mx::ioutils::getFileNames().
std::vector< std::string > mx::ioutils::getFileNames | ( | const std::string & | directory, |
const std::string & | extension | ||
) |
Get a list of file names from the specified directory, specifying the extension.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
[in] | directory | the path to the directory to search. Can not be empty. |
[in] | extension | the file name extension to search for, if "" then not used. Note that this must include the ".", as in ".ext". |
Definition at line 168 of file fileUtils.cpp.
References mx::ioutils::getFileNames().
std::vector< std::string > mx::ioutils::getFileNames | ( | const std::string & | directory, |
const std::string & | prefix, | ||
const std::string & | substr, | ||
const std::string & | extension | ||
) |
Get a list of file names from the specified directory, specifying a prefix, a substring to match, and an extension.
[in] | directory | the path to the directory to search. Can not be empty. |
[in] | prefix | the file name prefix (the beginning characters of the file name) to search for, if "" then not used. |
[in] | substr | a substring of the filename to earch for, if "" then not used. |
[in] | extension | the file name extension to search for, if "" then not used. Note that this must include the ".", as in".ext". |
Definition at line 85 of file fileUtils.cpp.
Referenced by mx::ioutils::getFileNames(), mx::improc::HCIobservation< _realT >::load_fileList(), mx::improc::HCIobservation< _realT >::load_RDIfileList(), mx::improc::ADIobservation< _realT, _derotFunctObj >::readPSFSub(), and mx::improc::HCIobservation< _realT >::readPSFSub().
std::string mx::ioutils::getSequentialFilename | ( | const std::string & | basename, |
const std::string & | extension = "" , |
||
const int | startat = 0 , |
||
int | ndigit = 4 |
||
) |
Get the next file in a numbered sequence.
Searches for files in the path designated by basename of the form basenameXXXXextension where the number of digits in XXXX is set by the ndigit parameter.
std::string | containing the next filename. |
[in] | basename | path and initial name of the file |
[in] | extension | [optional] extension to append after the number. Default is empty. |
[in] | startat | [optional] number to start the search from. Default is 0. |
[in] | ndigit | [optional] number of digits in string representation of the number. Default is 4. |
Definition at line 213 of file fileUtils.cpp.
Referenced by SCENARIO(), and mx::improc::HCIobservation< _realT >::writeFinim().
std::string mx::ioutils::parentPath | ( | const std::string & | fname | ) |
Get the parent path from a filename.
Definition at line 77 of file fileUtils.cpp.
Referenced by mx::astro::phoenixSpectrum< _units >::readSpectrum(), and mx::astro::rewritePhoenixSpectrum().
std::string mx::ioutils::pathFilename | ( | const std::string & | fname | ) |
Get the base filename.
Definition at line 71 of file fileUtils.cpp.
Referenced by mx::sys::gitRepo::getGitName(), mx::improc::ADIobservation< _realT, _derotFunctObj >::injectFake(), mx::improc::HCIobservation< _realT >::outputPreProcessed(), mx::improc::HCIobservation< _realT >::readWeights(), mx::improc::HCIobservation< _realT >::stdFitsHeader(), and mx::improc::HCIobservation< _realT >::threshold().
std::string mx::ioutils::pathStem | ( | const std::string & | fname | ) |
Get the stem of the filename.
Definition at line 65 of file fileUtils.cpp.