mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
fileName: moved file operation global function to fileOperation
This commit is contained in:
@ -1164,6 +1164,8 @@ Foam::label Foam::fileOperation::detectProcessorPath(const fileName& fName)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::fileOperation& Foam::fileHandler()
|
||||
{
|
||||
if (!fileOperation::fileHandlerPtr_.valid())
|
||||
@ -1203,4 +1205,44 @@ void Foam::fileHandler(autoPtr<fileOperation>& newHandlerPtr)
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::search(const word& file, const fileName& directory)
|
||||
{
|
||||
// Search the current directory for the file
|
||||
fileNameList files(fileHandler().readDir(directory));
|
||||
forAll(files, i)
|
||||
{
|
||||
if (files[i] == file)
|
||||
{
|
||||
return directory/file;
|
||||
}
|
||||
}
|
||||
|
||||
// If not found search each of the sub-directories
|
||||
fileNameList dirs(fileHandler().readDir(directory, fileName::DIRECTORY));
|
||||
forAll(dirs, i)
|
||||
{
|
||||
fileName path = search(file, directory/dirs[i]);
|
||||
if (path != fileName::null)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return fileName::null;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -536,6 +536,14 @@ const fileOperation& fileHandler();
|
||||
//- Reset file handler
|
||||
void fileHandler(autoPtr<fileOperation>&);
|
||||
|
||||
//- 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);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -27,7 +27,6 @@ License
|
||||
#include "wordList.H"
|
||||
#include "DynamicList.H"
|
||||
#include "OSspecific.H"
|
||||
#include "fileOperation.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -397,46 +396,4 @@ Foam::fileName Foam::operator/(const string& a, const string& b)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName Foam::search(const word& file, const fileName& directory)
|
||||
{
|
||||
// Search the current directory for the file
|
||||
fileNameList files(fileHandler().readDir(directory));
|
||||
forAll(files, i)
|
||||
{
|
||||
if (files[i] == file)
|
||||
{
|
||||
return directory/file;
|
||||
}
|
||||
}
|
||||
|
||||
// If not found search each of the sub-directories
|
||||
fileNameList dirs(fileHandler().readDir(directory, fileName::DIRECTORY));
|
||||
forAll(dirs, i)
|
||||
{
|
||||
fileName path = search(file, directory/dirs[i]);
|
||||
if (path != fileName::null)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
return fileName::null;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -242,14 +242,6 @@ 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);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Reference in New Issue
Block a user