Skip to content
Snippets Groups Projects
Commit af39491c authored by Henry Weller's avatar Henry Weller
Browse files

fileName: Added recursive directory search function

    //- 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);
parent ecb05dd6
Branches
Tags
No related merge requests found
......@@ -396,4 +396,33 @@ 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(readDir(directory));
forAll(files, i)
{
if (files[i] == file)
{
return directory/file;
}
}
// If not found search each of the sub-directories
fileNameList dirs(readDir(directory, fileName::DIRECTORY));
forAll(dirs, i)
{
fileName path = search(file, directory/dirs[i]);
if (path != fileName::null)
{
return path;
}
}
return fileName::null;
}
// ************************************************************************* //
......@@ -242,6 +242,12 @@ public:
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);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment