From 64da5dab55eeae1092170d9f7fd71590b14c0116 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Mon, 28 May 2018 22:14:22 +0100 Subject: [PATCH] fileName: Added cpFiles function //- Copy all the files from the source to the target directory void cpFiles(const fileName& srcDir, const fileName& targetDir); --- .../fileOperation/fileOperation.H | 28 +++++++++---------- .../primitives/strings/fileName/fileName.C | 15 +++++++++- .../primitives/strings/fileName/fileName.H | 4 ++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H index 57264736c..2f56e7094 100644 --- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H +++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.H @@ -50,13 +50,6 @@ class regIOobject; class objectRegistry; class Time; -// Description of processor directory naming: -// - processor directory naming -// - whether directory contains a range (so differs on different processors) -// - index in range -//typedef Tuple2> dirIndex; -//typedef List dirIndexList; - /*---------------------------------------------------------------------------*\ Class fileOperation Declaration \*---------------------------------------------------------------------------*/ @@ -83,9 +76,16 @@ public: PROCBASEINSTANCE, // as PROCBASEOBJECT but with instance PROCINSTANCE // as PROCOBJECT but with instance }; + static const NamedEnum pathTypeNames_; + //- Description of processor directory naming: + // - processor directory naming + // - whether directory contains a range + // (so differs on different processors) + // - index in range typedef Tuple2> dirIndex; + typedef List dirIndexList; @@ -298,13 +298,13 @@ public: //- Remove a directory and its contents virtual bool rmDir(const fileName&) const = 0; -// //- Open a shared library. Return handle to library. Print error -// // message if library cannot be loaded (check = true) -// virtual void* dlOpen -// ( -// const fileName& lib, -// const bool check = true -// ) const = 0; + // //- Open a shared library. Return handle to library. Print error + // // message if library cannot be loaded (check = true) + // virtual void* dlOpen + // ( + // const fileName& lib, + // const bool check = true + // ) const = 0; // (reg)IOobject functinality diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 49a188cbc..d240e65b4 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -426,4 +426,17 @@ Foam::fileName Foam::search(const word& file, const fileName& directory) } +void Foam::cpFiles(const fileName& srcDir, const fileName& targetDir) +{ + mkDir(targetDir); + + const fileNameList srcFiles(readDir(srcDir, fileName::FILE, true)); + + forAll(srcFiles, filei) + { + cp(srcDir/srcFiles[filei], targetDir); + } +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 9c7f7dc69..01765ce9e 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -242,12 +242,14 @@ public: //- Assemble words and fileNames as pathnames by adding a '/' separator fileName operator/(const string&, const string&); - //- Recursively search the given directory for the file // returning the path relative to the directory or // fileName::null if not found fileName search(const word& file, const fileName& directory); +//- Copy all the files from the source to the target directory +void cpFiles(const fileName& srcDir, const fileName& targetDir); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //