fileName: Added cpFiles function

//- Copy all the files from the source to the target directory
void cpFiles(const fileName& srcDir, const fileName& targetDir);
This commit is contained in:
Henry Weller
2018-05-28 22:14:22 +01:00
parent 03727e711d
commit 64da5dab55
3 changed files with 31 additions and 16 deletions

View File

@ -50,13 +50,6 @@ class regIOobject;
class objectRegistry; class objectRegistry;
class Time; 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<fileName, Tuple2<bool, label>> dirIndex;
//typedef List<dirIndex> dirIndexList;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class fileOperation Declaration Class fileOperation Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -83,9 +76,16 @@ public:
PROCBASEINSTANCE, // as PROCBASEOBJECT but with instance PROCBASEINSTANCE, // as PROCBASEOBJECT but with instance
PROCINSTANCE // as PROCOBJECT but with instance PROCINSTANCE // as PROCOBJECT but with instance
}; };
static const NamedEnum<pathType, 12> pathTypeNames_; static const NamedEnum<pathType, 12> pathTypeNames_;
//- Description of processor directory naming:
// - processor directory naming
// - whether directory contains a range
// (so differs on different processors)
// - index in range
typedef Tuple2<fileName, Tuple2<pathType, label>> dirIndex; typedef Tuple2<fileName, Tuple2<pathType, label>> dirIndex;
typedef List<dirIndex> dirIndexList; typedef List<dirIndex> dirIndexList;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License 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);
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -242,12 +242,14 @@ public:
//- Assemble words and fileNames as pathnames by adding a '/' separator //- Assemble words and fileNames as pathnames by adding a '/' separator
fileName operator/(const string&, const string&); fileName operator/(const string&, const string&);
//- Recursively search the given directory for the file //- Recursively search the given directory for the file
// returning the path relative to the directory or // returning the path relative to the directory or
// fileName::null if not found // fileName::null if not found
fileName search(const word& file, const fileName& directory); 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);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //