67 static bool cleanFileName
74 const auto maxLen = str.length();
80 if (maxLen > 2 && str[0] ==
'\\' && str[1] ==
'\\')
86 auto top = std::string::npos;
89 for (
auto src = nChar; src < maxLen; )
111 if (
c ==
'/' && top == std::string::npos)
117 if (doClean && prev ==
'/')
135 const char c1 = str[src];
138 if (
c1 ==
'/' ||
c1 ==
'\\')
151 || str[src+1] ==
'/' || str[src+1] ==
'\\' 163 && top != std::string::npos
164 && (parent = str.rfind(
'/', nChar-2)) != std::string::npos
181 str[nChar++] = prev =
c;
185 if (doClean && nChar > 1 && str[nChar-1] ==
'/')
191 return changed || (nChar != maxLen);
201 return cleanFileName(str,
true,
false);
207 const std::string& str,
212 cleanFileName(out, doClean,
true);
219 const std::string& s1,
220 const std::string& s2,
224 const auto n1 = s1.length();
225 const auto n2 = s2.length();
228 out.reserve(n1 + n2 + 1);
232 if (n1 && n2 && s1.back() != delim && s2.front() != delim)
253 const auto n1 = s1.length();
254 const auto n2 = s2.length();
257 while (i1 < n1 && i2 < n2)
261 if (s1[i1] != s2[i2])
271 while (s1[i1] ==
'/');
277 while (s2[i2] ==
'/');
282 return (i1 == n1 && i2 == n2);
292 else if (
s.back() ==
'~')
298 auto dot = find_ext(
s);
309 !
s.compare(
dot, npos,
"bak") || !
s.compare(
dot, npos,
"BAK")
310 || !
s.compare(
dot, npos,
"old") || !
s.compare(
dot, npos,
"save")
320 for (
const word& item : list)
322 len += 1 + item.length();
326 for (
const word& item : list)
330 if (length())
operator+=(
'/');
340 for (
const word& item : list)
342 len += 1 + item.length();
346 for (
const word& item : list)
350 if (length())
operator+=(
'/');
367 if (checkGzip && (Type::UNDEFINED == t) && size())
379 if (!isAbsolute(*
this))
398 auto beg = str.rfind(
'/');
399 auto dot = str.rfind(
'.');
410 if (
dot != npos &&
dot <= beg)
417 return str.substr(beg);
420 return str.substr(beg,
dot - beg);
426 const auto len = newName.length();
430 auto beg = rfind(
'/');
439 replace(beg, length()-beg, newName);
449 const fileName& parent,
453 const auto top = parent.length();
454 const fileName&
f = *
this;
467 top && (
f.length() > (top+1)) &&
f[top] ==
'/' 468 &&
f.starts_with(parent)
473 const auto trailing =
f.
find(
'/', top+1);
475 if (npos != trailing)
477 switch (trailing-top-1)
481 if (!compare((top+1), 6,
"system"))
483 return "<system>"/
f.substr(trailing+1);
489 if (!compare((top+1), 8,
"constant"))
491 return "<constant>"/
f.substr(trailing+1);
497 return "<case>"/
f.substr(top+1);
501 return f.substr(top+1);
504 else if (caseTag &&
f.length() && !
f.isAbsolute())
506 const auto trailing =
f.
find(
'/');
508 if (npos != trailing)
514 if (!compare(0, 6,
"system"))
516 return "<system>"/
f.substr(trailing+1);
522 if (!compare(0, 8,
"constant"))
524 return "<constant>"/
f.substr(trailing+1);
539 const auto parsed = stringOps::split<string>(*
this, delim);
544 for (
const auto& sub : parsed)
547 words[i] = sub.str();
562 const auto parsed = stringOps::split<string>(*
this, delim);
566 if (cmpt == std::string::npos)
568 return parsed.last().str();
570 else if (cmpt < parsed.size())
572 return parsed[cmpt].str();
592 if (
s.back() !=
'/' && other.front() !=
'/')
600 else if (other.size())
620 if (s1.back() ==
'/' || s2.front() ==
'/')
622 return fileName(s1 + s2);
626 return fileName(s1 +
'/' + s2);
658 return directory/item;
static int debug
Debugging.
A class for handling file names.
fileName & operator/=(const string &other)
Append a path element with '/' separator.
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
bool clean()
Cleanup filename (inplace)
word stem() const
Return basename, without extension.
int debugSwitch(const char *name, const int deflt=0)
Lookup debug switch or add default value.
static const fileName null
An empty fileName.
Type type(bool followLink=true, bool checkGzip=false) const
Return the directory entry type: UNDEFINED, FILE, DIRECTORY (or SYMLINK).
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
static const char *const typeName
The typeName.
static bool equals(const std::string &s1, const std::string &s2)
This is a specialized (possibly slower) version of compare() that ignores duplicate or trailing slash...
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
void dot(FieldField< Field1, typename innerProduct< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
word component(const size_type cmpt, const char delim='/') const
Return a single component of the path or empty if out of range.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
bool assign(const token &tok)
Assign from word or string token.
fileName relative(const fileName &parent, const bool caseTag=false) const
Return a relative name by stripping off the parent directory where possible.
fileName()=default
Default construct.
A class for handling words, derived from Foam::string.
graph_traits< Graph >::vertices_size_type size_type
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
fileName & toAbsolute()
Convert from relative to absolute.
wordList components(const char delim='/') const
Return path components as wordList.
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
static bool valid(char c)
Is this character valid for a fileName?
static fileName concat(const std::string &s1, const std::string &s2, const char delim='/')
Join two strings with a path separator ('/' by default).
fileName & replace_name(const word &newName)
Replace basename (part beyond last /) with a new name.
List< word > wordList
List of word.
static int allowSpaceInFileName
Allow space character in fileName. To be used with caution.
bool isBackup() const
Return true if file name ends with "~", ".bak", ".old", ".save".
static fileName validate(const std::string &, const bool doClean=true)
Construct fileName without invalid characters, possibly applying other transformations such as changi...
const dimensionedScalar c
Speed of light in a vacuum.
triangles reserve(surf.size())
fileName cwd()
The physical or logical current working directory path name.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::Type::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
Type
Enumerations to handle directory entry types.