diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 97ba294bdd95ebdddb6f86d654b042ea1c2f7b1b..1953935f3c70f699bcc69f2d797d9ab82af81b03 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -824,7 +824,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink) // If dest is a directory, create the destination file name. if (destFile.type() == fileName::DIRECTORY) { - destFile = destFile/src.name(); + destFile /= src.name(); } // Make sure the destination directory exists. @@ -864,7 +864,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink) // If dest is a directory, create the destination file name. if (destFile.type() == fileName::DIRECTORY) { - destFile = destFile/src.name(); + destFile /= src.name(); } // Make sure the destination directory exists. @@ -880,7 +880,7 @@ bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink) // If dest is a directory, create the destination file name. if (destFile.type() == fileName::DIRECTORY) { - destFile = destFile/src.components().last(); + destFile /= src.components().last(); } // Make sure the destination directory exists. diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index f77302f521bc4c1733d1b1a045f50c1c7563ab0d..009baae72848e5f4ef7130ad69921216b4f16f2a 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -533,6 +533,30 @@ void Foam::fileName::operator=(const char* str) } +Foam::fileName& Foam::fileName::operator/=(const string& other) +{ + fileName& s = *this; + + if (s.size()) + { + if (other.size()) + { + // Two non-empty strings: can concatenate + + s.append("/"); + s.append(other); + } + } + else if (other.size()) + { + // Or, if the first string is empty + s = other; + } + + return *this; +} + + // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // Foam::fileName Foam::operator/(const string& a, const string& b) diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 437afde91e433e3c8ad3812796ef99e9ff978979..9201a7b21251e3384ea011fbc3dce93d7b60eebb 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -130,7 +130,7 @@ public: fileName(Istream& is); - // Member functions + // Member Functions //- Is this character valid for a fileName? inline static bool valid(char c); @@ -188,7 +188,7 @@ public: fileName clean() const; - // Interrogation + // Interrogation //- Return the file type: FILE, DIRECTORY, LINK or UNDEFINED. // LINK is only returned if followLink=false @@ -210,7 +210,7 @@ public: inline bool isBackup() const; - // Decomposition + // Decomposition //- Return basename (part beyond last /), including its extension // The result normally corresponds to a Foam::word @@ -316,7 +316,7 @@ public: // Member operators - // Assignment + // Assignment //- Copy, no character validation required void operator=(const fileName& str); @@ -334,6 +334,13 @@ public: void operator=(const char* str); + // Other operators + + //- Append a path element with '/' separator. + // No '/' separator is added if this or the argument are empty. + fileName& operator/=(const string& other); + + // IOstream operators friend Istream& operator>>(Istream& is, fileName& fn);