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);
This commit is contained in:
parent
ecb05dd66b
commit
af39491c04
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user