A class for handling file names. More...
Public Types | |
enum | Type { UNDEFINED = 0, FILE = 1, DIRECTORY = 2, LINK = 4 } |
Enumerations to handle directory entry types. More... | |
Public Member Functions | |
fileName ()=default | |
Default construct. More... | |
fileName (const fileName &)=default | |
Copy construct. More... | |
fileName (fileName &&)=default | |
Move construct. More... | |
fileName (const word &s) | |
Copy construct from word. More... | |
fileName (word &&s) | |
Move construct from word. More... | |
fileName (const string &s, bool doStrip=true) | |
Copy construct from string. More... | |
fileName (string &&s, bool doStrip=true) | |
Move construct from string. More... | |
fileName (const std::string &s, bool doStrip=true) | |
Copy construct from std::string. More... | |
fileName (std::string &&s, bool doStrip=true) | |
Move construct from std::string. More... | |
fileName (const char *s, bool doStrip=true) | |
Copy construct from character array. More... | |
fileName (const UList< word > &list) | |
Construct by concatenating elements of wordList separated by '/'. More... | |
fileName (std::initializer_list< word > list) | |
Construct by concatenating words separated by '/'. More... | |
fileName (Istream &is) | |
Construct from Istream. More... | |
bool | assign (const token &tok) |
Assign from word or string token. More... | |
void | stripInvalid () |
Strip invalid characters. More... | |
bool | clean () |
Cleanup filename (inplace) More... | |
Type | type (bool followLink=true, bool checkGzip=false) const |
bool | isAbsolute () const |
fileName & | toAbsolute () |
Convert from relative to absolute. More... | |
bool | isBackup () const |
Return true if file name ends with "~", ".bak", ".old", ".save". More... | |
word | name () const |
Return basename (part beyond last /), including its extension. More... | |
word | nameLessExt () const |
Return basename, without extension. More... | |
word | name (const bool noExt) const |
Deprecated(2017-03) return basename, optionally without extension. More... | |
fileName | path () const |
Return directory path name (part before last /) More... | |
bool | hasPath () const |
Return true if it contains a '/' character. More... | |
bool | removePath () |
Remove leading path, returning true if string changed. More... | |
fileName | relative (const fileName &parent, const bool caseTag=false) const |
fileName | lessExt () const |
Return file name without extension (part before last .) More... | |
word | ext () const |
Return file name extension (part after last .) More... | |
fileName & | ext (const word &ending) |
Append a '.' and the ending, and return the object. More... | |
wordList | components (const char delim='/') const |
Return path components as wordList. More... | |
word | component (const size_type cmpt, const char delim='/') const |
Return a single component of the path or empty if out of range. More... | |
fileName & | operator= (const fileName &str) |
Copy assignment, no character validation required. More... | |
fileName & | operator= (fileName &&str) |
Move assignment, no character validation required. More... | |
fileName & | operator= (const word &str) |
Copy assignment, no character validation required. More... | |
fileName & | operator= (word &&str) |
Move assignment, no character validation required. More... | |
fileName & | operator= (const string &str) |
Copy assignment, stripping invalid characters. More... | |
fileName & | operator= (string &&str) |
Move assignment, stripping invalid characters. More... | |
fileName & | operator= (const std::string &str) |
Copy assignment, stripping invalid characters. More... | |
fileName & | operator= (std::string &&str) |
Move assignment, stripping invalid characters. More... | |
fileName & | operator= (const char *str) |
Copy, stripping invalid characters. More... | |
fileName & | operator/= (const string &other) |
Append a path element with '/' separator. More... | |
bool | hasExt () const |
Various checks for extensions. More... | |
bool | hasExt (const char *ending) const |
Various checks for extensions. More... | |
bool | hasExt (const std::string &ending) const |
Various checks for extensions. More... | |
bool | hasExt (const wordRe &ending) const |
Various checks for extensions. More... | |
bool | removeExt () |
Remove extension, returning true if string changed. More... | |
![]() | |
string ()=default | |
Default construct. More... | |
string (const std::string &str) | |
Copy construct from std::string. More... | |
string (std::string &&str) | |
Move construct from std::string. More... | |
string (const char *str) | |
Construct as copy of character array. More... | |
string (const char *str, const size_type len) | |
Construct as copy with a maximum number of characters. More... | |
string (const char c) | |
Construct from a single character. More... | |
string (const size_type len, const char c) | |
Construct fill copies of a single character. More... | |
string (Istream &is) | |
Construct from Istream. More... | |
bool | match (const std::string &text) const |
Test for equality. More... | |
string & | replace (const std::string &s1, const std::string &s2, size_type pos=0) |
string & | replaceAll (const std::string &s1, const std::string &s2, size_type pos=0) |
string & | replaceAny (const std::string &s1, const char c2, size_type pos=0) |
string & | expand (const bool allowEmpty=false) |
bool | removeRepeated (const char character) |
Remove repeated characters. More... | |
bool | removeStart (const std::string &text) |
Remove the given text from the start of the string. More... | |
bool | removeStart (const char c) |
Remove leading character, unless string is a single character. More... | |
bool | removeEnd (const std::string &text) |
Remove the given text from the end of the string. More... | |
bool | removeEnd (const char c) |
Remove trailing character, unless string is a single character. More... | |
void | swap (std::string &str) |
Swap contents. Self-swapping is a no-op. More... | |
bool | operator() (const std::string &text) const |
Test for equality. Allows use as a predicate. More... | |
bool | starts_with (const std::string &s) const |
True if string starts with the given prefix (cf. C++20) More... | |
bool | starts_with (const char c) const |
True if string starts with the given character (cf. C++20) More... | |
bool | ends_with (const std::string &s) const |
True if string ends with the given suffix (cf. C++20) More... | |
bool | ends_with (const char c) const |
True if string ends with the given character (cf. C++20) More... | |
size_type | count (const char c) const |
bool | startsWith (const std::string &s) const |
Deprecated(2019-11) More... | |
bool | endsWith (const std::string &s) const |
Deprecated(2019-11) More... | |
bool | removeTrailing (const char c) |
Deprecated(2019-11) More... | |
Static Public Member Functions | |
static bool | valid (char c) |
Is this character valid for a fileName? More... | |
static fileName | validate (const std::string &, const bool doClean=true) |
static fileName | concat (const std::string &s1, const std::string &s2, const char delim='/') |
Join two strings with a path separator ('/' by default). More... | |
static bool | equals (const std::string &s1, const std::string &s2) |
static bool | clean (std::string &str) |
static bool | isAbsolute (const std::string &str) |
static bool | isBackup (const std::string &str) |
Return true if string ends with "~", ".bak", ".old", ".save". More... | |
static std::string | name (const std::string &str) |
Return basename (part beyond last /), including its extension. More... | |
static std::string | nameLessExt (const std::string &str) |
Return basename, without extension. More... | |
static std::string | path (const std::string &str) |
Return directory path name (part before last /) More... | |
![]() | |
template<class StringType > | |
static bool | valid (const std::string &str) |
Does the string contain valid characters only? More... | |
template<class StringType > | |
static bool | stripInvalid (std::string &str) |
Strip invalid characters from the given string. More... | |
template<class StringType > | |
static StringType | validate (const std::string &str) |
Return a valid String from the given string. More... | |
Static Public Attributes | |
static const char *const | typeName = "fileName" |
The typeName. More... | |
static int | debug |
Debugging. More... | |
static int | allowSpaceInFileName |
Allow space character in fileName. To be used with caution. More... | |
static const fileName | null |
An empty fileName. More... | |
![]() | |
static const char *const | typeName = "string" |
The type name "string". More... | |
static int | debug |
The debug flag. More... | |
static const string | null |
An empty string. More... | |
Additional Inherited Members | |
![]() | |
std::string::size_type | find_ext () const |
Find position of a file extension dot, return npos on failure. More... | |
word | ext () const |
Return file name extension (part after last .) More... | |
bool | ext (const word &ending) |
Append a '.' and the ending. More... | |
bool | hasPath () const |
Return true if it contains a '/' character. More... | |
bool | hasExt () const |
Return true if it has an extension or simply ends with a '.'. More... | |
bool | hasExt (const char *ending) const |
Return true if the extension is the same as the given ending. More... | |
bool | hasExt (const std::string &ending) const |
Return true if the extension is the same as the given ending. More... | |
bool | hasExt (const wordRe &ending) const |
Return true if the extension matches the given ending. More... | |
bool | removeExt () |
Remove extension, returning true if string changed. More... | |
bool | removePath () |
Remove leading path, returning true if string changed. More... | |
![]() | |
static std::string::size_type | find_ext (const std::string &str) |
Find position of a file extension dot, return npos on failure. More... | |
template<class PrimitiveType > | |
static std::string::size_type | string_printf (std::string &output, const char *fmt, const PrimitiveType &val) |
A printf-style formatter for a primitive. More... | |
template<class PrimitiveType > | |
static std::string::size_type | string_printf (std::string &output, const std::string &fmt, const PrimitiveType &val) |
A printf-style formatter for a primitive. More... | |
A class for handling file names.
A fileName is a string of characters without whitespace or quotes. A fileName can be
The string::expand() method expands environment variables, etc,
Definition at line 73 of file fileName.H.
enum Type |
Enumerations to handle directory entry types.
Enumerator | |
---|---|
UNDEFINED | Undefined type. |
FILE | A file. |
DIRECTORY | A directory. |
LINK | A symlink. |
Definition at line 80 of file fileName.H.
|
default |
Default construct.
Copy construct from word.
Definition at line 33 of file fileNameI.H.
Move construct from word.
Definition at line 39 of file fileNameI.H.
Copy construct from string.
Definition at line 45 of file fileNameI.H.
References fileName::stripInvalid().
Move construct from string.
Definition at line 56 of file fileNameI.H.
References fileName::stripInvalid().
Copy construct from std::string.
Definition at line 67 of file fileNameI.H.
References fileName::stripInvalid().
Move construct from std::string.
Definition at line 78 of file fileNameI.H.
References fileName::stripInvalid().
Copy construct from character array.
Definition at line 89 of file fileNameI.H.
References fileName::stripInvalid().
Construct by concatenating elements of wordList separated by '/'.
Definition at line 317 of file fileName.C.
Construct by concatenating words separated by '/'.
Definition at line 337 of file fileName.C.
Construct from Istream.
Definition at line 34 of file fileNameIO.C.
Assign from word or string token.
Definition at line 42 of file fileNameIO.C.
References Foam::FieldOps::assign(), token::isQuotedString(), token::isWord(), token::stringToken(), and token::wordToken().
Referenced by Foam::expandLeadingTag(), and Foam::operator>>().
|
inlinestatic |
Is this character valid for a fileName?
Definition at line 102 of file fileNameI.H.
References Foam::constant::universal::c, and Foam::isspace().
Referenced by FileName::valid().
|
static |
Construct fileName without invalid characters, possibly applying other transformations such as changing the path separator, removing duplicate or trailing slashes, etc.
Definition at line 206 of file fileName.C.
Referenced by Foam::argList::get< Foam::fileName >().
|
static |
Join two strings with a path separator ('/' by default).
No separator is added if either argument is an empty string or if the arguments already had the path separator at the junction. Invalid characters are not stripped (ie, retained).
Definition at line 218 of file fileName.C.
Referenced by dictionary::add(), dictionary::dictionary(), and scene::write().
|
static |
This is a specialized (possibly slower) version of compare() that ignores duplicate or trailing slashes.
Definition at line 245 of file fileName.C.
|
inline |
Strip invalid characters.
Definition at line 113 of file fileNameI.H.
References Foam::expressions::patchExpr::debug, Foam::endl(), and Foam::exit().
Referenced by fileName::fileName().
|
static |
Cleanup filename string, possibly applies other transformations such as changing the path separator etc.
Changes back-slash to forward-slash path separator, while preserving windows UNC:
\\server\abc\def --> \\server/abc/def
Removes trailing slash:
/ --> / /abc/ --> /abc
Removes repeated slashes, but preserves UNC:
/abc////def --> /abc/def \\server\abc////def --> \\server/abc/def
Removes "/./"
(current directory), except for leading one:
/abc/def/./ghi/. --> /abc/def/ghi abc/def/./ --> abc/def ./abc/ --> ./abc
Removes "/../"
(parent directory), except for leading one:
/abc/def/../ghi/jkl/nmo/.. --> /abc/ghi/jkl abc/../def/ghi/../jkl --> abc/../def/jkl
Definition at line 199 of file fileName.C.
Referenced by dictionary::cfindScopedDict(), externalFileCoupler::externalFileCoupler(), IOobject::fileNameComponents(), meshRefinement::findRegions(), averageNeighbourFvGeometryScheme::movePoints(), argList::parse(), probes::prepare(), abort::read(), shortestPathSet::shortestPathSet(), and mappedPatchBase::subRegistry().
bool clean | ( | ) |
Cleanup filename (inplace)
Definition at line 390 of file fileName.C.
Referenced by dictionary::makeScopedDict(), and entry::New().
Foam::fileName::Type type | ( | bool | followLink = true , |
bool | checkGzip = false |
||
) | const |
Return the directory entry type: UNDEFINED, FILE, DIRECTORY (or LINK).
followLink | when false it will return LINK for a symlink rather than following it. |
checkGzip | add an additional test for a gzip FILE |
Definition at line 360 of file fileName.C.
Referenced by Foam::cp(), Foam::mv(), and fvMeshDistribute::printFieldInfo().
|
inlinestatic |
Return true if filename starts with a '/' or '\' or (windows-only) with a filesystem-root
Definition at line 136 of file fileNameI.H.
Referenced by pointNoise::calculate(), surfaceNoise::calculate(), chemkinReader::chemkinReader(), uncollatedFileOperation::filePathInfo(), masterUncollatedFileOperation::filePathInfo(), argList::parse(), abort::read(), surfaceFormatsCore::relativeFilePath(), includeEtcEntry::resolveEtcFile(), includeEntry::resolveFile(), collatedFileOperation::writeObject(), and triSurfaceMesh::writeObject().
|
inline |
Return true if filename is absolute, which means it starts with a '/' or '\' or (windows-only) with a filesystem-root
Definition at line 158 of file fileNameI.H.
Foam::fileName & toAbsolute | ( | ) |
Convert from relative to absolute.
Definition at line 377 of file fileName.C.
References Foam::cwd(), and f().
|
static |
Return true if string ends with "~", ".bak", ".old", ".save".
Definition at line 286 of file fileName.C.
References Foam::dot(), and s.
|
inline |
Return true if file name ends with "~", ".bak", ".old", ".save".
Definition at line 164 of file fileNameI.H.
|
inlinestatic |
Return basename (part beyond last /), including its extension.
The result normally corresponds to a Foam::word
Behaviour compared to /usr/bin/basename:
input name() basename ----- ------ -------- "" "" "" "abc" "abc" "abc" "/" "" "/" "/abc" "abc" "abc" "abc/def" "def" "def" "/abc/def" "def" "def" "/abc/def/" "" "def" "/abc/../def" "def" "def"
Definition at line 199 of file fileNameI.H.
Referenced by fileMonitorWatcher::addWatch(), seriesWriter::append(), argList::argList(), dynamicCode::copyOrCreateFiles(), Foam::cp(), Foam::mv(), Time::New(), processorPolyPatch::order(), probes::prepare(), fileOperation::processorsPath(), ensightCase::setTime(), triSurface::triSurfInstance(), timeVaryingMappedFixedValuePointPatchField< Type >::updateCoeffs(), MappedFile< scalar >::value(), ensightSetWriter< Type >::write(), abaqusWriter::write(), ensightWriter::writeCollated(), nastranWriter::writeTemplate(), streamLineBase::writeToFile(), and ensightWriter::writeUncollated().
|
inline |
Return basename (part beyond last /), including its extension.
Definition at line 212 of file fileNameI.H.
Referenced by entry::New(), and scene::write().
|
static |
Return basename, without extension.
The result normally corresponds to a Foam::word
Definition at line 396 of file fileName.C.
References Foam::dot().
Referenced by dlLibraryTable::basename(), surfaceNoise::calculate(), seriesWriter::print(), and seriesWriter::scan().
|
inline |
Return basename, without extension.
Definition at line 224 of file fileNameI.H.
Referenced by vtmWriter::append().
Deprecated(2017-03) return basename, optionally without extension.
Definition at line 286 of file fileName.H.
|
inlinestatic |
Return directory path name (part before last /)
The result normally corresponds to a Foam::fileName
Behaviour compared to /usr/bin/dirname:
input path() dirname ----- ------ ------- "" "." "." "abc" "." "." "/" "/" "/" "/abc" "/" "/" "abc/def" "abc" "abc" "/abc/def" "/abc" "/abc" "/abc/def/" "/abc/def" "/abc" "/abc/../def" "/abc/.." "/abc/.."
Definition at line 176 of file fileNameI.H.
Referenced by fileMonitorWatcher::addWatch(), timeVaryingMappedFixedValuePointPatchField< Type >::checkTable(), chemkinReader::chemkinReader(), dynamicCode::copyOrCreateFiles(), Foam::cp(), dynamicCode::createMakeFiles(), dynamicCode::createMakeOptions(), includeEntry::execute(), isoSurfacePoint::isoSurfacePoint(), seriesWriter::load(), Foam::mkDir(), Time::New(), pointHistory::pointHistory(), fileOperation::processorsPath(), surfMesh::removeFiles(), polyMesh::removeFiles(), seriesWriter::scan(), seriesWriter::write(), proxyWriter::write(), x3dWriter::write(), starcdWriter::write(), foamWriter::write(), rawWriter::write(), vtkWriter::write(), abaqusWriter::write(), nastranWriter::write(), vtmWriter::write(), ensightWriter::writeCollated(), dynamicCode::writeDigest(), isoAdvection::writeIsoFaces(), triSurfaceMesh::writeObject(), distributedTriSurfaceMesh::writeObject(), Foam::vtk::writePointSet(), abaqusWriter::writeTemplate(), rawWriter::writeTemplate(), nastranWriter::writeTemplate(), foamWriter::writeTemplate(), starcdWriter::writeTemplate(), boundaryDataWriter::writeTemplate(), x3dWriter::writeTemplate(), streamLineBase::writeToFile(), and ensightWriter::writeUncollated().
|
inline |
Return directory path name (part before last /)
Definition at line 193 of file fileNameI.H.
References path().
Referenced by entry::New().
|
inline |
Return true if it contains a '/' character.
Definition at line 170 of file fileNameI.H.
References string::hasPath().
|
inline |
Remove leading path, returning true if string changed.
Definition at line 243 of file fileNameI.H.
References string::removePath().
Referenced by seriesWriter::append().
Foam::fileName relative | ( | const fileName & | parent, |
const bool | caseTag = false |
||
) | const |
Return a relative name by stripping off the parent directory where possible.
parent | the parent directory |
caseTag | replace the parent with <case> for later use with expand(), or prefix <case> if the file name was not an absolute location |
Definition at line 425 of file fileName.C.
References f().
|
inline |
Return file name without extension (part before last .)
Definition at line 230 of file fileNameI.H.
Referenced by Foam::dlOpen(), STARCDsurfaceFormat< Face >::read(), STARCDedgeFormat::read(), ensightSetWriter< Type >::write(), STARCDsurfaceFormat< Face >::write(), FIREMeshWriter::write(), STARCDedgeFormat::write(), Foam::vtk::writePointSet(), and abaqusWriter::writeTemplate().
|
inline |
Return file name extension (part after last .)
Definition at line 218 of file fileNameI.H.
References string::ext().
Referenced by Foam::dlOpen(), seriesWriter::load(), seriesWriter::print(), edgeMesh::read(), extendedEdgeMesh::read(), seriesWriter::scan(), FIREMeshWriter::write(), proxyWriter::write(), x3dWriter::write(), starcdWriter::write(), rawWriter::write(), vtkWriter::write(), abaqusWriter::write(), nastranWriter::write(), abaqusWriter::writeTemplate(), rawWriter::writeTemplate(), nastranWriter::writeTemplate(), starcdWriter::writeTemplate(), x3dWriter::writeTemplate(), and NURBS3DSurface::writeVTK().
|
inline |
Append a '.' and the ending, and return the object.
The '.' and ending will not be added when the ending is empty, or when the file name is empty or ended with a '/'.
Definition at line 249 of file fileNameI.H.
References string::ext().
Foam::wordList components | ( | const char | delim = '/' | ) | const |
Return path components as wordList.
Behaviour:
input components() ----- ------------ "" () "." (".") "abc" ("abc") "/abc" ("abc") "abc/def" ("abc", "def") "/abc/def" ("abc", "def") "/abc/def/" ("abc", "def")
Definition at line 461 of file fileName.C.
Referenced by dictionary::cfindScopedDict(), and mappedPatchBase::subRegistry().
Foam::word component | ( | const size_type | cmpt, |
const char | delim = '/' |
||
) | const |
Return a single component of the path or empty if out of range.
The location npos
returns the last component
Definition at line 481 of file fileName.C.
|
inline |
Copy assignment, no character validation required.
Self-assignment is a no-op.
Definition at line 258 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Move assignment, no character validation required.
Self-assignment is a no-op.
Definition at line 269 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Copy assignment, no character validation required.
Definition at line 280 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Move assignment, no character validation required.
Definition at line 287 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Copy assignment, stripping invalid characters.
Definition at line 294 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Move assignment, stripping invalid characters.
Definition at line 302 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Copy assignment, stripping invalid characters.
Definition at line 310 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Move assignment, stripping invalid characters.
Definition at line 318 of file fileNameI.H.
References Foam::FieldOps::assign().
|
inline |
Copy, stripping invalid characters.
Definition at line 326 of file fileNameI.H.
References Foam::FieldOps::assign().
Foam::fileName & operator/= | ( | const string & | other | ) |
Append a path element with '/' separator.
No '/' separator is added if this or the argument are empty.
Definition at line 506 of file fileName.C.
References s.
|
inline |
Various checks for extensions.
Definition at line 56 of file stringI.H.
Referenced by vtmWriter::append(), STLCore::isBinaryName(), seriesWriter::load(), Foam::printSourceFileAndLine(), seriesWriter::scan(), seriesWriter::write(), vtmWriter::write(), and Foam::vtk::writePointSet().
|
inline |
Remove extension, returning true if string changed.
Definition at line 96 of file stringI.H.
Referenced by fileWriter::open(), and seriesWriter::scan().
|
static |
The typeName.
Definition at line 92 of file fileName.H.
|
static |
Debugging.
Definition at line 95 of file fileName.H.
|
static |
Allow space character in fileName. To be used with caution.
Definition at line 98 of file fileName.H.
|
static |
An empty fileName.
Definition at line 101 of file fileName.H.
Referenced by vtmWriter::add(), Time::dbDir(), fileOperation::filePath(), functionObjectList::findDict(), masterUncollatedFileOperation::fileOrNullOp::operator()(), argList::parse(), fileOperation::processorsPath(), syncObjects::read(), nullWriter::write(), proxyWriter::write(), mappedPatchBase::write(), and surfaceWriter::writeTemplate().