From b060378dca689544307c13f2a285182681be397a Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Mon, 12 Apr 2021 22:56:20 +0200
Subject: [PATCH] ENH: improve consistency of fileName handling
 windows/non-windows (#2057)

- wrap command-line retrieval of fileName with an implicit validate.

  Instead of this:
      fileName input(args[1]);
      fileName other(args["someopt"]);

  Now use this:
      auto input = args.get<fileName>(1);
      auto other = args.get<fileName>("someopt");

  which adds a fileName::validate on the inputs

  Because of how it is implemented, it will automatically also apply
  to argList getOrDefault<fileName>, readIfPresent<fileName> etc.

- adjust fileName::validate and clean to handle backslash conversion.
  This makes it easier to ensure that path names arising from MS-Windows
  are consistently handled internally.

- dictionarySearch: now check for initial '/' directly instead of
  relying on fileName isAbsolute(), which now does more things

BREAKING: remove fileName::clean() const method

- relying on const/non-const to control the behaviour (inplace change
  or return a copy) is too fragile and the const version was
  almost never used.

  Replace:
      fileName sanitized = constPath.clean();

  With:
      fileName sanitized(constPath);
      sanitized.clean());

STYLE: test empty() instead of comparing with fileName::null
---
 applications/test/List3/Test-List3.C          |   6 +-
 .../test/PackedList/Test-PackedList.C         |   5 +-
 .../Test-checkDecomposePar.C                  |   5 +-
 .../test/codeStream/Test-codeStream.C         |   5 +-
 .../coordinateSystem/Test-coordinateSystem.C  |   6 +-
 applications/test/copyFile/Test-copyFile.C    |   6 +-
 .../Test-decomposedBlockData.C                |   3 +-
 .../test/dictionary/Test-dictionary.C         |   5 +-
 .../test/dictionaryCopy/Test-dictionaryCopy.C |   2 +-
 .../dictionaryTokens/Test-dictionaryTokens.C  |   4 +-
 .../test/dynamicLibrary/Test-dynamicLibrary.C |   4 +-
 applications/test/exprEntry/Test-exprEntry.C  |   4 +-
 applications/test/fileName/Test-fileName.C    |   4 +-
 .../test/fileNameClean/Test-fileNameClean.C   |  18 +-
 .../test/fstreamPointer/Test-fstreamPointer.C |   4 +-
 applications/test/mvBak/Test-mvBak.C          |   5 +-
 .../test/plotFunction1/Test-plotFunction1.C   |   4 +-
 applications/test/regex1/Test-regex1.C        |   2 +-
 applications/test/spline/Test-spline.C        |   6 +-
 .../Test-surfaceIntersection.C                |   6 +-
 .../test/surfaceReading/Test-surfaceReading.C |   4 +-
 .../test/surfaceWriter/Test-surfaceWriter.C   |   6 +-
 .../vtkSeriesWriter/Test-vtkSeriesWriter.C    |   4 +-
 .../mesh/conversion/ansysToFoam/ansysToFoam.L |   4 +-
 .../mesh/conversion/ccm/ccmToFoam/ccmToFoam.C |   4 +-
 .../mesh/conversion/cfx4ToFoam/cfx4ToFoam.C   |   4 +-
 .../mesh/conversion/datToFoam/datToFoam.C     |   2 +-
 .../mesh/conversion/fireToFoam/fireToFoam.C   |   4 +-
 .../fluent3DMeshToFoam/fluent3DMeshToFoam.L   |   2 +-
 .../fluentMeshToFoam/fluentMeshToFoam.L       |   4 +-
 .../conversion/foamToSurface/foamToSurface.C  |   4 +-
 .../conversion/gambitToFoam/gambitToFoam.L    |   4 +-
 .../mesh/conversion/gmshToFoam/gmshToFoam.C   |   4 +-
 .../ideasUnvToFoam/ideasUnvToFoam.C           |   2 +-
 .../mesh/conversion/mshToFoam/mshToFoam.C     |   3 +-
 .../netgenNeutralToFoam/netgenNeutralToFoam.C |   4 +-
 .../conversion/plot3dToFoam/plot3dToFoam.C    |   4 +-
 .../mesh/conversion/star4ToFoam/star4ToFoam.C |   4 +-
 .../conversion/tetgenToFoam/tetgenToFoam.C    |   4 +-
 .../vtkUnstructuredToFoam.C                   |   3 +-
 .../conformalVoronoiMesh.C                    |   6 +-
 .../foamyHexMeshSurfaceSimplify.C             |   4 +-
 .../foamyHexMeshSurfaceSimplify_non_octree.C  |   6 +-
 .../foamyMesh/foamyQuadMesh/foamyQuadMesh.C   |   3 +-
 .../generation/snappyHexMesh/snappyHexMesh.C  |   2 +-
 .../mesh/manipulation/checkMesh/checkTools.C  |   6 +-
 .../manipulation/insideCells/insideCells.C    |   6 +-
 .../manipulation/mergeMeshes/mergeMeshes.C    |  10 +-
 .../mesh/manipulation/objToVTK/objToVTK.C     |   6 +-
 .../mesh/manipulation/setSet/setSet.C         |   4 +-
 .../foamDictionary/foamDictionary.C           |   4 +-
 .../foamHasLibrary/foamHasLibrary.C           |   4 +-
 .../dataConversion/smapToFoam/smapToFoam.C    |   2 +-
 .../lumpedPointMovement/lumpedPointMovement.C |   4 +-
 .../preProcessing/mapFields/mapFields.C       |   4 +-
 .../preProcessing/mapFieldsPar/mapFieldsPar.C |   4 +-
 .../utilities/surface/surfaceAdd/surfaceAdd.C |  12 +-
 .../surface/surfaceCheck/surfaceCheck.C       |   4 +-
 .../surface/surfaceClean/surfaceClean.C       |  10 +-
 .../surface/surfaceCoarsen/surfaceCoarsen.C   |   8 +-
 .../surface/surfaceConvert/surfaceConvert.C   |   6 +-
 .../surfaceFeatureConvert.C                   |   6 +-
 .../surface/surfaceFind/surfaceFind.C         |   4 +-
 .../surface/surfaceInertia/surfaceInertia.C   |   4 +-
 .../surface/surfaceInflate/surfaceInflate.C   |  12 +-
 .../surfaceLambdaMuSmooth.C                   |  14 +-
 .../surfaceMeshConvert/surfaceMeshConvert.C   |   6 +-
 .../surfaceMeshExport/surfaceMeshExport.C     |   6 +-
 .../surfaceMeshExtract/surfaceMeshExtract.C   |   4 +-
 .../surfaceMeshImport/surfaceMeshImport.C     |   6 +-
 .../surface/surfaceMeshInfo/surfaceMeshInfo.C |   4 +-
 .../surface/surfaceOrient/surfaceOrient.C     |   8 +-
 .../surfacePointMerge/surfacePointMerge.C     |   8 +-
 .../surfaceRedistributePar.C                  |   4 +-
 .../surfaceRefineRedGreen.C                   |   6 +-
 .../surfaceSplitByPatch/surfaceSplitByPatch.C |   4 +-
 .../surfaceSplitByTopology.C                  |   9 +-
 .../surfaceSplitNonManifolds.C                |   6 +-
 .../surface/surfaceSubset/surfaceSubset.C     |  12 +-
 .../surface/surfaceToPatch/surfaceToPatch.C   |   4 +-
 .../surfaceTransformPoints.C                  |   6 +-
 .../adiabaticFlameT/adiabaticFlameT.C         |   3 +-
 .../chemkinToFoam/chemkinToFoam.C             |  14 +-
 .../equilibriumFlameT/equilibriumFlameT.C     |   3 +-
 .../mixtureAdiabaticFlameT.C                  |   3 +-
 src/OpenFOAM/db/IOobject/IOobject.C           |   4 +-
 src/OpenFOAM/db/dictionary/dictionarySearch.C |  28 +-
 .../db/functionObjects/writeFile/writeFile.C  |   3 +-
 src/OpenFOAM/global/argList/argList.C         |   5 +-
 src/OpenFOAM/global/argList/argList.H         |   4 +-
 src/OpenFOAM/global/argList/argListI.H        |   6 +-
 .../primitives/strings/fileName/fileName.C    | 268 +++++++++---------
 .../primitives/strings/fileName/fileName.H    |  71 ++---
 .../primitives/strings/fileName/fileNameI.H   |  26 +-
 .../averageNeighbourFvGeometryScheme.C        |   4 +-
 .../field/externalCoupled/externalCoupled.C   |   8 +-
 .../lagrangian/dataCloud/dataCloud.C          |   2 +-
 .../lagrangian/vtkCloud/vtkCloud.C            |   2 +-
 src/functionObjects/utilities/abort/abort.C   |   9 +-
 .../utilities/ensightWrite/ensightWrite.C     |   2 +-
 .../utilities/vtkWrite/vtkWrite.C             |   2 +-
 .../rotorDiskSource/bladeModel/bladeModel.C   |   6 +-
 .../profileModel/profileModel.C               |   4 +-
 .../meshRefinement/meshRefinement.C           |   6 +-
 src/meshTools/coupling/externalFileCoupler.C  |   6 +-
 .../mappedPolyPatch/mappedPatchBase.C         |  11 +-
 src/sampling/probes/probes.C                  |   3 +-
 .../sampledSet/shortestPath/shortestPathSet.C |   4 +-
 .../chemkinReader/chemkinReader.C             |   4 +-
 109 files changed, 482 insertions(+), 455 deletions(-)

diff --git a/applications/test/List3/Test-List3.C b/applications/test/List3/Test-List3.C
index 68550082116..e23b36579be 100644
--- a/applications/test/List3/Test-List3.C
+++ b/applications/test/List3/Test-List3.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -101,7 +101,7 @@ int main(int argc, char *argv[])
         {
             if (true)
             {
-                IFstream is(args[argi]);
+                IFstream is(args.get<fileName>(argi));
 
                 Info<< nl << nl
                     << "read from " << is.name() << nl << endl;
@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
 
             if (true)
             {
-                IFstream is(args[argi]);
+                IFstream is(args.get<fileName>(argi));
 
                 Info<< nl << nl
                     << "read from " << is.name() << nl << endl;
diff --git a/applications/test/PackedList/Test-PackedList.C b/applications/test/PackedList/Test-PackedList.C
index b6f5582a839..771be2a3552 100644
--- a/applications/test/PackedList/Test-PackedList.C
+++ b/applications/test/PackedList/Test-PackedList.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -125,9 +126,9 @@ int main(int argc, char *argv[])
     }
 
 
-    for (label argI=1; argI < args.size(); ++argI)
+    for (label argi=1; argi < args.size(); ++argi)
     {
-        const string& srcFile = args[argI];
+        const auto srcFile = args.get<fileName>(argi);
         Info<< nl << "reading " << srcFile << nl;
 
         IFstream ifs(srcFile);
diff --git a/applications/test/checkDecomposePar/Test-checkDecomposePar.C b/applications/test/checkDecomposePar/Test-checkDecomposePar.C
index 805b57b9ec7..41e46a9cf6a 100644
--- a/applications/test/checkDecomposePar/Test-checkDecomposePar.C
+++ b/applications/test/checkDecomposePar/Test-checkDecomposePar.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017-2020 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -74,8 +74,7 @@ int main(int argc, char *argv[])
 
     #include "setRootCase.H"
 
-    const fileName decompFile = args[1];
-
+    const auto decompFile = args.get<fileName>(1);
     const bool region     = args.found("region");
     const bool allRegions = args.found("allRegions");
     const bool verbose    = args.found("verbose");
diff --git a/applications/test/codeStream/Test-codeStream.C b/applications/test/codeStream/Test-codeStream.C
index fc3b656436a..49b04ac2f1d 100644
--- a/applications/test/codeStream/Test-codeStream.C
+++ b/applications/test/codeStream/Test-codeStream.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -59,9 +60,9 @@ int main(int argc, char *argv[])
     else
     {
         IOobject::writeDivider(Info);
-        for (label argI=1; argI < args.size(); ++argI)
+        for (label argi=1; argi < args.size(); ++argi)
         {
-            const string& dictFile = args[argI];
+            const auto dictFile = args.get<fileName>(argi);
             IFstream is(dictFile);
 
             dictionary dict(is);
diff --git a/applications/test/coordinateSystem/Test-coordinateSystem.C b/applications/test/coordinateSystem/Test-coordinateSystem.C
index 402038e6a92..7931a97abfc 100644
--- a/applications/test/coordinateSystem/Test-coordinateSystem.C
+++ b/applications/test/coordinateSystem/Test-coordinateSystem.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -179,7 +179,7 @@ int main(int argc, char *argv[])
 
         for (label argi=1; argi < args.size(); ++argi)
         {
-            const string& dictFile = args[argi];
+            const auto dictFile = args.get<fileName>(argi);
             IFstream is(dictFile);
 
             dictionary inputDict(is);
@@ -201,7 +201,7 @@ int main(int argc, char *argv[])
     {
         for (label argi=1; argi < args.size(); ++argi)
         {
-            const string& dictFile = args[argi];
+            const auto dictFile = args.get<fileName>(argi);
             IFstream is(dictFile);
 
             dictionary inputDict(is);
diff --git a/applications/test/copyFile/Test-copyFile.C b/applications/test/copyFile/Test-copyFile.C
index c3be05dc139..616aefc410d 100644
--- a/applications/test/copyFile/Test-copyFile.C
+++ b/applications/test/copyFile/Test-copyFile.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -135,8 +135,8 @@ int main(int argc, char *argv[])
     args.readIfPresent("maxPath", maxPath);
     #endif
 
-    const fileName srcFile(fileName::validate(args[1]));
-    const fileName dstFile(fileName::validate(args[2]));
+    const auto srcFile = args.get<fileName>(1);
+    const auto dstFile = args.get<fileName>(2);
     const fileName tmpFile(dstFile + Foam::name(pid()));
 
     Info<< "src   : " << srcFile << nl
diff --git a/applications/test/decomposedBlockData/Test-decomposedBlockData.C b/applications/test/decomposedBlockData/Test-decomposedBlockData.C
index 9edc26ee7e2..2402055210d 100644
--- a/applications/test/decomposedBlockData/Test-decomposedBlockData.C
+++ b/applications/test/decomposedBlockData/Test-decomposedBlockData.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2017 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -54,7 +55,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    const fileName file(args[1]);
+    const auto file = args.get<fileName>(1);
 
     Info<< "Reading " << file << nl << endl;
     decomposedBlockData data
diff --git a/applications/test/dictionary/Test-dictionary.C b/applications/test/dictionary/Test-dictionary.C
index 5e12dbd7ef3..1c5c7a30e11 100644
--- a/applications/test/dictionary/Test-dictionary.C
+++ b/applications/test/dictionary/Test-dictionary.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2012 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -123,9 +124,9 @@ int main(int argc, char *argv[])
     else
     {
         IOobject::writeDivider(Info);
-        for (label argI=1; argI < args.size(); ++argI)
+        for (label argi=1; argi < args.size(); ++argi)
         {
-            const string& dictFile = args[argI];
+            const auto dictFile = args.get<fileName>(argi);
             IFstream is(dictFile);
 
             dictionary dict(is);
diff --git a/applications/test/dictionaryCopy/Test-dictionaryCopy.C b/applications/test/dictionaryCopy/Test-dictionaryCopy.C
index 264c88e3e8d..4ab58d3a0a4 100644
--- a/applications/test/dictionaryCopy/Test-dictionaryCopy.C
+++ b/applications/test/dictionaryCopy/Test-dictionaryCopy.C
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
 
     for (label argi=1; argi < args.size(); ++argi)
     {
-        const string& dictFile = args[argi];
+        const auto dictFile = args.get<fileName>(argi);
         IFstream is(dictFile);
 
         dictionary input(is);
diff --git a/applications/test/dictionaryTokens/Test-dictionaryTokens.C b/applications/test/dictionaryTokens/Test-dictionaryTokens.C
index 3760124cab1..1b8967b7638 100644
--- a/applications/test/dictionaryTokens/Test-dictionaryTokens.C
+++ b/applications/test/dictionaryTokens/Test-dictionaryTokens.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
 
     for (label argi=1; argi < args.size(); ++argi)
     {
-        IFstream is(args[argi]);
+        IFstream is(args.get<fileName>(argi));
 
         dictionary dict(is);
 
diff --git a/applications/test/dynamicLibrary/Test-dynamicLibrary.C b/applications/test/dynamicLibrary/Test-dynamicLibrary.C
index ee7009b9618..0e878a5616c 100644
--- a/applications/test/dynamicLibrary/Test-dynamicLibrary.C
+++ b/applications/test/dynamicLibrary/Test-dynamicLibrary.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -70,7 +70,7 @@ int main(int argc, char *argv[])
 
     for (int argi = 1; argi < args.size(); ++argi)
     {
-        const fileName libName(fileName::validate(args[argi]));
+        const auto libName = args.get<fileName>(argi);
 
         if (libName.empty())
         {
diff --git a/applications/test/exprEntry/Test-exprEntry.C b/applications/test/exprEntry/Test-exprEntry.C
index e5b76da7b70..1f14bbf45aa 100644
--- a/applications/test/exprEntry/Test-exprEntry.C
+++ b/applications/test/exprEntry/Test-exprEntry.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
     {
         IOobject::writeDivider(Info);
 
-        IFstream is(args[argi]);
+        IFstream is(args.get<fileName>(argi));
 
         const dictionary dict(is);
 
diff --git a/applications/test/fileName/Test-fileName.C b/applications/test/fileName/Test-fileName.C
index 5c368dbdfb7..c6bdd486df5 100644
--- a/applications/test/fileName/Test-fileName.C
+++ b/applications/test/fileName/Test-fileName.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2017 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -60,7 +60,7 @@ unsigned testClean(std::initializer_list<Pair<std::string>> tests)
         const std::string& expected = test.second();
 
         fileName cleaned(test.first());
-        cleaned.clean();
+        cleaned.clean();  // Remove unneeded ".."
 
         if (cleaned == expected)
         {
diff --git a/applications/test/fileNameClean/Test-fileNameClean.C b/applications/test/fileNameClean/Test-fileNameClean.C
index f368778a447..b6a23325ce6 100644
--- a/applications/test/fileNameClean/Test-fileNameClean.C
+++ b/applications/test/fileNameClean/Test-fileNameClean.C
@@ -5,7 +5,8 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2011-2017 OpenFOAM Foundation
+    Copyright (C) 2011 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -24,11 +25,10 @@ License
     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 
 Application
-    fileNameCleanTest
+    Test-fileNameClean
 
 Description
 
-
 \*---------------------------------------------------------------------------*/
 
 #include "argList.H"
@@ -51,7 +51,7 @@ void printCleaning(fileName& pathName)
     Info<< "components  = " << flatOutput(pathName.components()) << nl;
     Info<< "component 2 = " << pathName.component(2) << nl;
 
-    pathName.clean();
+    pathName.clean();  // Remove unneeded ".."
 
     Info<< "cleaned  = " << pathName << nl
         << "  path() = " << pathName.path() << nl
@@ -94,9 +94,15 @@ int main(int argc, char *argv[])
         printCleaning(pathName);
     }
 
-    for (label argI=1; argI < args.size(); ++argI)
+    for (label argi=1; argi < args.size(); ++argi)
     {
-        pathName = args[argI];
+        fileName fn(args[argi], false); // no strip
+        Info<< "Input = " << fn << nl;
+        fn.clean();  // Remove unneeded ".."
+        Info<< "cleaned = " << fn << nl;
+        Info<< "get = " << args.get<fileName>(argi) << nl;
+
+        pathName = fileName::validate(args[argi]);
         printCleaning(pathName);
     }
 
diff --git a/applications/test/fstreamPointer/Test-fstreamPointer.C b/applications/test/fstreamPointer/Test-fstreamPointer.C
index 6f12abd9a01..2cad909ace1 100644
--- a/applications/test/fstreamPointer/Test-fstreamPointer.C
+++ b/applications/test/fstreamPointer/Test-fstreamPointer.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
 
     for (label argi = 1; argi < args.size(); ++argi)
     {
-        const fileName inputName(args[argi]);
+        const auto inputName = args.get<fileName>(argi);
 
         InfoErr<< "input: " << inputName;
 
diff --git a/applications/test/mvBak/Test-mvBak.C b/applications/test/mvBak/Test-mvBak.C
index 9c9b6c7172d..7c6ff169ff1 100644
--- a/applications/test/mvBak/Test-mvBak.C
+++ b/applications/test/mvBak/Test-mvBak.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -53,9 +54,9 @@ int main(int argc, char *argv[])
 
     label ok = 0;
 
-    for (label argI=1; argI < args.size(); ++argI)
+    for (label argi=1; argi < args.size(); ++argi)
     {
-        const string& srcFile = args[argI];
+        const auto srcFile = args.get<fileName>(argi);
 
         if (args.found("ext"))
         {
diff --git a/applications/test/plotFunction1/Test-plotFunction1.C b/applications/test/plotFunction1/Test-plotFunction1.C
index 9ddc5cc0246..99bc8769a80 100644
--- a/applications/test/plotFunction1/Test-plotFunction1.C
+++ b/applications/test/plotFunction1/Test-plotFunction1.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
 
     for (label argi=1; argi < args.size(); ++argi)
     {
-        IFstream is(args[argi]);
+        IFstream is(args.get<fileName>(argi));
 
         dictionary dict(is);
 
diff --git a/applications/test/regex1/Test-regex1.C b/applications/test/regex1/Test-regex1.C
index b84d7d00a39..9f917355a96 100644
--- a/applications/test/regex1/Test-regex1.C
+++ b/applications/test/regex1/Test-regex1.C
@@ -375,7 +375,7 @@ int main(int argc, char *argv[])
 
     for (label argi = 1; argi < args.size(); ++argi)
     {
-        IFstream is(args[argi]);
+        IFstream is(args.get<fileName>(argi));
         List<regexTest> tests(is);
 
         Info<< "Test expressions:" << tests << endl;
diff --git a/applications/test/spline/Test-spline.C b/applications/test/spline/Test-spline.C
index 4d9af262dcb..9785da0fdb7 100644
--- a/applications/test/spline/Test-spline.C
+++ b/applications/test/spline/Test-spline.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2013 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -76,9 +76,9 @@ int main(int argc, char *argv[])
         useCatmullRom = true;
     }
 
-    for (label argI=1; argI < args.size(); ++argI)
+    for (label argi=1; argi < args.size(); ++argi)
     {
-        const string& srcFile = args[argI];
+        const auto srcFile = args.get<fileName>(argi);
         Info<< nl << "reading " << srcFile << nl;
         IFstream ifs(srcFile);
 
diff --git a/applications/test/surfaceIntersection/Test-surfaceIntersection.C b/applications/test/surfaceIntersection/Test-surfaceIntersection.C
index c3e2731b937..e0c6c218b3d 100644
--- a/applications/test/surfaceIntersection/Test-surfaceIntersection.C
+++ b/applications/test/surfaceIntersection/Test-surfaceIntersection.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017-2020 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -139,13 +139,13 @@ int main(int argc, char *argv[])
 
     const word outputFile(args.executable() + ".obj");
 
-    const fileName surf1Name(args[1]);
+    const auto surf1Name = args.get<fileName>(1);
     triSurface surf1 = loadSurface(runTime, surf1Name, scaleFactor)();
     Info<< surf1Name << " statistics:" << endl;
     surf1.writeStats(Info);
     Info<< endl;
 
-    const fileName surf2Name(args[2]);
+    const auto surf2Name = args.get<fileName>(2);
     triSurface surf2 = loadSurface(runTime, surf2Name, scaleFactor)();
     Info<< surf2Name << " statistics:" << endl;
     surf2.writeStats(Info);
diff --git a/applications/test/surfaceReading/Test-surfaceReading.C b/applications/test/surfaceReading/Test-surfaceReading.C
index ea6572039cf..bd0c39d12b0 100644
--- a/applications/test/surfaceReading/Test-surfaceReading.C
+++ b/applications/test/surfaceReading/Test-surfaceReading.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
 
     #include "setRootCase.H"
 
-    const fileName importName = args[1];
+    const auto importName = args.get<fileName>(1);
 
     word ext;
     if (!args.readIfPresent("ext", ext))
diff --git a/applications/test/surfaceWriter/Test-surfaceWriter.C b/applications/test/surfaceWriter/Test-surfaceWriter.C
index c1826f2fe17..3d8ee9cf258 100644
--- a/applications/test/surfaceWriter/Test-surfaceWriter.C
+++ b/applications/test/surfaceWriter/Test-surfaceWriter.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2019-2020 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -68,8 +68,8 @@ int main(int argc, char *argv[])
 
     #include "setRootCase.H"
 
-    const fileName importName = args[1];
-    const fileName exportName = args[2];
+    const auto importName = args.get<fileName>(1);
+    const auto exportName = args.get<fileName>(2);
 
     if (importName == exportName)
     {
diff --git a/applications/test/vtkSeriesWriter/Test-vtkSeriesWriter.C b/applications/test/vtkSeriesWriter/Test-vtkSeriesWriter.C
index 1cc4ad30264..c01b249f733 100644
--- a/applications/test/vtkSeriesWriter/Test-vtkSeriesWriter.C
+++ b/applications/test/vtkSeriesWriter/Test-vtkSeriesWriter.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
 
     for (label argi=1; argi < args.size(); ++argi)
     {
-        const auto& input = args[argi];
+        const auto input = args.get<fileName>(argi);
 
         Info << "load from " << input << nl;
 
diff --git a/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L b/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L
index cafcdf67adc..66cb8534a5b 100644
--- a/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L
+++ b/applications/utilities/mesh/conversion/ansysToFoam/ansysToFoam.L
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2020 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -327,7 +327,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    const fileName ansysFile(args[1]);
+    const auto ansysFile = args.get<fileName>(1);
     std::ifstream ansysStream(ansysFile);
 
     if (!ansysStream)
diff --git a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C
index 14855f09315..876a6d59bec 100644
--- a/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C
+++ b/applications/utilities/mesh/conversion/ccm/ccmToFoam/ccmToFoam.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -225,7 +225,7 @@ int main(int argc, char *argv[])
     }
 
     // CCM reader for reading geometry/solution
-    ccm::reader reader(args[1], rOpts);
+    ccm::reader reader(args.get<fileName>(1), rOpts);
 
     // list the geometry information
     if (optList)
diff --git a/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C b/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C
index 903767ab43b..3039c16a566 100644
--- a/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C
+++ b/applications/utilities/mesh/conversion/cfx4ToFoam/cfx4ToFoam.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    IFstream cfxFile(args[1]);
+    IFstream cfxFile(args.get<fileName>(1));
 
     // Read the cfx information using a fixed format reader.
     // Comments in the file are in C++ style, so the stream parser will remove
diff --git a/applications/utilities/mesh/conversion/datToFoam/datToFoam.C b/applications/utilities/mesh/conversion/datToFoam/datToFoam.C
index 2e3dd0d4524..8a526ab5cf9 100644
--- a/applications/utilities/mesh/conversion/datToFoam/datToFoam.C
+++ b/applications/utilities/mesh/conversion/datToFoam/datToFoam.C
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    std::ifstream plot3dFile(args[1]);
+    std::ifstream plot3dFile(args.get<fileName>(1));
 
     string line;
     std::getline(plot3dFile, line);
diff --git a/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C b/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C
index 021907f0967..b3809ff1603 100644
--- a/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C
+++ b/applications/utilities/mesh/conversion/fireToFoam/fireToFoam.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -103,7 +103,7 @@ int main(int argc, char *argv[])
 
     fileFormats::FIREMeshReader reader
     (
-        args[1],
+        args.get<fileName>(1),
         // Default no scaling
         args.getOrDefault<scalar>("scale", 1)
     );
diff --git a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L
index 066da1368a1..98d751ee0df 100644
--- a/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L
+++ b/applications/utilities/mesh/conversion/fluent3DMeshToFoam/fluent3DMeshToFoam.L
@@ -835,7 +835,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    const fileName fluentFile = args[1];
+    const auto fluentFile = args.get<fileName>(1);
     IFstream fluentStream(fluentFile);
 
     if (!fluentStream)
diff --git a/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L b/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L
index 8623da54ecf..8d70aa39f96 100644
--- a/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L
+++ b/applications/utilities/mesh/conversion/fluentMeshToFoam/fluentMeshToFoam.L
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -912,7 +912,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    const fileName fluentFile = args[1];
+    const auto fluentFile = args.get<fileName>(1);
     std::ifstream fluentStream(fluentFile);
 
     if (!fluentStream)
diff --git a/applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C b/applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C
index 17703601d86..53b359a2f2c 100644
--- a/applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C
+++ b/applications/utilities/mesh/conversion/foamToSurface/foamToSurface.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
 
     #include "setRootCase.H"
 
-    fileName exportName = args[1];
+    auto exportName = args.get<fileName>(1);
 
     const scalar scaleFactor = args.getOrDefault<scalar>("scale", 0);
     const bool doTriangulate = args.found("tri");
diff --git a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L
index cbd4172c750..f8a226a6358 100644
--- a/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L
+++ b/applications/utilities/mesh/conversion/gambitToFoam/gambitToFoam.L
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -653,7 +653,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    const fileName gambitFile = args[1];
+    const auto gambitFile = args.get<fileName>(1);
     std::ifstream gambitStream(gambitFile);
 
     if (!gambitStream)
diff --git a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C
index 02a17f42352..b7e6909ff27 100644
--- a/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C
+++ b/applications/utilities/mesh/conversion/gmshToFoam/gmshToFoam.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -1325,7 +1325,7 @@ int main(int argc, char *argv[])
     }
 
     const bool keepOrientation = args.found("keepOrientation");
-    IFstream inFile(args[1]);
+    IFstream inFile(args.get<fileName>(1));
 
     // Storage for points
     pointField points;
diff --git a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C
index 6c2d2188b6c..4c3fe7cc477 100644
--- a/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C
+++ b/applications/utilities/mesh/conversion/ideasUnvToFoam/ideasUnvToFoam.C
@@ -666,7 +666,7 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    const fileName ideasName = args[1];
+    const auto ideasName = args.get<fileName>(1);
     IFstream inFile(ideasName);
 
     if (!inFile.good())
diff --git a/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C b/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C
index 20088ce4ca2..1bfa8f7183a 100644
--- a/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C
+++ b/applications/utilities/mesh/conversion/mshToFoam/mshToFoam.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -77,7 +78,7 @@ int main(int argc, char *argv[])
     #include "createTime.H"
 
     const bool readHex = args.found("hex");
-    IFstream mshStream(args[1]);
+    IFstream mshStream(args.get<fileName>(1));
 
     label nCells;
     mshStream >> nCells;
diff --git a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C
index cbae422f00f..81e0280d22e 100644
--- a/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C
+++ b/applications/utilities/mesh/conversion/netgenNeutralToFoam/netgenNeutralToFoam.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    IFstream str(args[1]);
+    IFstream str(args.get<fileName>(1));
 
     //
     // Read nodes.
diff --git a/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C b/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C
index 78e8381bb63..1a95f8fec2e 100644
--- a/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C
+++ b/applications/utilities/mesh/conversion/plot3dToFoam/plot3dToFoam.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -111,7 +111,7 @@ int main(int argc, char *argv[])
 
     #include "createTime.H"
 
-    IFstream plot3dFile(args[1]);
+    IFstream plot3dFile(args.get<fileName>(1));
 
     // Read the plot3d information using a fixed format reader.
     // Comments in the file are in C++ style, so the stream parser will remove
diff --git a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C
index 24a6c28f705..b48f1b6bd05 100644
--- a/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C
+++ b/applications/utilities/mesh/conversion/star4ToFoam/star4ToFoam.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
 
 
     // Remove extensions and/or trailing '.'
-    const fileName prefix = fileName(args[1]).lessExt();
+    const auto prefix = args.get<fileName>(1).lessExt();
 
 
     fileFormats::STARCDMeshReader reader
diff --git a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C
index 55ac13b40ca..1d457708d84 100644
--- a/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C
+++ b/applications/utilities/mesh/conversion/tetgenToFoam/tetgenToFoam.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    const fileName prefix = args[1];
+    const auto prefix = args.get<fileName>(1);
     const bool readFaceFile = !args.found("noFaceFile");
 
     const fileName nodeFile(prefix + ".node");
diff --git a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C
index 377458839f7..cb8f5577349 100644
--- a/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C
+++ b/applications/utilities/mesh/conversion/vtkUnstructuredToFoam/vtkUnstructuredToFoam.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2015 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -65,7 +66,7 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    IFstream mshStream(args[1]);
+    IFstream mshStream(args.get<fileName>(1));
 
     vtkUnstructuredReader reader(runTime, mshStream);
 
diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C
index 00a843e5312..136967f73b6 100644
--- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C
+++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2012-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -289,7 +289,7 @@ void Foam::conformalVoronoiMesh::insertSurfacePointPairs
         }
     }
 
-    if (foamyHexMeshControls().objOutput() && fName != fileName::null)
+    if (foamyHexMeshControls().objOutput() && !fName.empty())
     {
         DelaunayMeshTools::writeOBJ(time().path()/fName, pts);
     }
@@ -324,7 +324,7 @@ void Foam::conformalVoronoiMesh::insertEdgePointGroups
         }
     }
 
-    if (foamyHexMeshControls().objOutput() && fName != fileName::null)
+    if (foamyHexMeshControls().objOutput() && !fName.empty())
     {
         DelaunayMeshTools::writeOBJ(time().path()/fName, pts);
     }
diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify.C
index 699c0f1a7d8..2a355d70c1c 100644
--- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify.C
+++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2012-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2020 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -378,7 +378,7 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    const fileName exportName = args[1];
+    const auto exportName = args.get<fileName>(1);
 
     Info<< "Reading surfaces as specified in the foamyHexMeshDict and"
         << " writing a re-sampled surface to " << exportName
diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify_non_octree.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify_non_octree.C
index 611bc527930..1cfd57f9e8c 100644
--- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify_non_octree.C
+++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshSurfaceSimplify/foamyHexMeshSurfaceSimplify_non_octree.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2012-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -64,8 +64,8 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    const labelVector n(args.get<labelVector>(1));
-    const fileName exportName = args[2];
+    const auto n = args.get<labelVector>(1);
+    const auto exportName = args.get<fileName>(2);
 
     Info<< "Reading surfaces as specified in the foamyHexMeshDict and"
         << " writing re-sampled " << n << " to " << exportName
diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C
index 82f0ab9731e..919b8120713 100644
--- a/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C
+++ b/applications/utilities/mesh/generation/foamyMesh/foamyQuadMesh/foamyQuadMesh.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -97,7 +98,7 @@ int main(int argc, char *argv[])
 
     if (args.found("pointsFile"))
     {
-        mesh.insertPoints(args["pointsFile"]);
+        mesh.insertPoints(args.get<fileName>("pointsFile"));
     }
     else
     {
diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C
index b9fedffe615..1218dadddef 100644
--- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C
+++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C
@@ -541,7 +541,7 @@ void extractSurface
           ? runTime.globalPath()/outFileName
           : runTime.path()/outFileName
         );
-        globalCasePath.clean();
+        globalCasePath.clean();  // Remove unneeded ".."
 
         Info<< "Writing merged surface to " << globalCasePath << endl;
 
diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C
index e7ab6c2d17f..ad29e420dc3 100644
--- a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C
+++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C
@@ -306,7 +306,7 @@ void Foam::mergeAndWrite
       / mesh.pointsInstance()
       / set.name()
     );
-    outputDir.clean();
+    outputDir.clean();  // Remove unneeded ".."
 
     mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
 }
@@ -399,7 +399,7 @@ void Foam::mergeAndWrite
       / mesh.pointsInstance()
       / set.name()
     );
-    outputDir.clean();
+    outputDir.clean();  // Remove unneeded ".."
 
     mergeAndWrite(mesh, writer, set.name(), setPatch, outputDir);
 }
@@ -498,7 +498,7 @@ void Foam::mergeAndWrite
           / mesh.pointsInstance()
           // set.name()
         );
-        outputDir.clean();
+        outputDir.clean();  // Remove unneeded ".."
         mkDir(outputDir);
 
         fileName outputFile(outputDir/writer.getFileName(points, wordList()));
diff --git a/applications/utilities/mesh/manipulation/insideCells/insideCells.C b/applications/utilities/mesh/manipulation/insideCells/insideCells.C
index a3d19eb384f..07b4a629d2e 100644
--- a/applications/utilities/mesh/manipulation/insideCells/insideCells.C
+++ b/applications/utilities/mesh/manipulation/insideCells/insideCells.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -66,8 +66,8 @@ int main(int argc, char *argv[])
     #include "createTime.H"
     #include "createPolyMesh.H"
 
-    const fileName surfName = args[1];
-    const fileName setName  = args[2];
+    const auto surfName = args.get<fileName>(1);
+    const auto setName  = args.get<fileName>(2);
 
     // Read surface
     Info<< "Reading surface from " << surfName << endl;
diff --git a/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C b/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C
index 92b38c546b5..5fa4a4f626a 100644
--- a/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C
+++ b/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -45,7 +45,7 @@ using namespace Foam;
 
 void getRootCase(fileName& casePath)
 {
-    casePath.clean();
+    casePath.clean();  // Remove unneeded ".."
 
     if (casePath.empty() || casePath == ".")
     {
@@ -56,7 +56,7 @@ void getRootCase(fileName& casePath)
     {
         // avoid relative cases ending in '..' - makes for very ugly names
         casePath = cwd()/casePath;
-        casePath.clean();
+        casePath.clean();  // Remove unneeded ".."
     }
 }
 
@@ -102,8 +102,8 @@ int main(int argc, char *argv[])
 
     const bool overwrite = args.found("overwrite");
 
-    fileName masterCase = args[1];
-    fileName addCase = args[2];
+    auto masterCase = args.get<fileName>(1);
+    auto addCase = args.get<fileName>(2);
 
     const word masterRegion =
         args.getOrDefault<word>("masterRegion", polyMesh::defaultRegion);
diff --git a/applications/utilities/mesh/manipulation/objToVTK/objToVTK.C b/applications/utilities/mesh/manipulation/objToVTK/objToVTK.C
index 8965219067c..4ff92cf77a8 100644
--- a/applications/utilities/mesh/manipulation/objToVTK/objToVTK.C
+++ b/applications/utilities/mesh/manipulation/objToVTK/objToVTK.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2015 OpenFOAM Foundation
-    Copyright (C) 2019-2020 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -123,8 +123,8 @@ int main(int argc, char *argv[])
     argList::addArgument("vtk-file", "The output vtk file");
     argList args(argc, argv);
 
-    const fileName objName = args[1];
-    const fileName outName = args[2];
+    const auto objName = args.get<fileName>(1);
+    const auto outName = args.get<fileName>(2);
 
     std::ifstream OBJfile(objName);
 
diff --git a/applications/utilities/mesh/manipulation/setSet/setSet.C b/applications/utilities/mesh/manipulation/setSet/setSet.C
index 1473bf293fa..b866b07cb25 100644
--- a/applications/utilities/mesh/manipulation/setSet/setSet.C
+++ b/applications/utilities/mesh/manipulation/setSet/setSet.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2018 OpenFOAM Foundation
-    Copyright (C) 2017-2020 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -793,7 +793,7 @@ int main(int argc, char *argv[])
 
         if (batch)
         {
-            const fileName batchFile = args["batch"];
+            const auto batchFile = args.get<fileName>("batch");
 
             Info<< "Reading commands from file " << batchFile << endl;
 
diff --git a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C
index 97eeb2ccbaa..fddf9b20c2f 100644
--- a/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C
+++ b/applications/utilities/miscellaneous/foamDictionary/foamDictionary.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2016-2017 OpenFOAM Foundation
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -373,7 +373,7 @@ int main(int argc, char *argv[])
         }
     }
 
-    const fileName dictFileName(args[1]);
+    const auto dictFileName = args.get<fileName>(1);
 
     autoPtr<IFstream> dictFile(new IFstream(dictFileName));
     if (!dictFile().good())
diff --git a/applications/utilities/miscellaneous/foamHasLibrary/foamHasLibrary.C b/applications/utilities/miscellaneous/foamHasLibrary/foamHasLibrary.C
index 07243cac400..398b2397163 100644
--- a/applications/utilities/miscellaneous/foamHasLibrary/foamHasLibrary.C
+++ b/applications/utilities/miscellaneous/foamHasLibrary/foamHasLibrary.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
 
     for (int argi = 1; argi < args.size(); ++argi)
     {
-        const fileName libName(fileName::validate(args[argi]));
+        const auto libName = args.get<fileName>(argi);  // with validate
 
         if (libName.empty())
         {
diff --git a/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C b/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C
index af91270a9e5..49bb2b1239a 100644
--- a/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C
+++ b/applications/utilities/postProcessing/dataConversion/smapToFoam/smapToFoam.C
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
 
     #include "createNamedMesh.H"
 
-    IFstream smapFile(args[1]);
+    IFstream smapFile(args.get<fileName>(1));
 
     if (!smapFile.good())
     {
diff --git a/applications/utilities/postProcessing/lumped/lumpedPointMovement/lumpedPointMovement.C b/applications/utilities/postProcessing/lumped/lumpedPointMovement/lumpedPointMovement.C
index 1925d5d5699..ef5597dcae0 100644
--- a/applications/utilities/postProcessing/lumped/lumpedPointMovement/lumpedPointMovement.C
+++ b/applications/utilities/postProcessing/lumped/lumpedPointMovement/lumpedPointMovement.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -150,7 +150,7 @@ int main(int argc, char *argv[])
 
     args.readIfPresent("visual-length", lumpedPointState::visLength);
 
-    const fileName responseFile(args[1]);
+    const auto responseFile = args.get<fileName>(1);
 
     // ----------------------------------------------------------------------
     // Slave mode
diff --git a/applications/utilities/preProcessing/mapFields/mapFields.C b/applications/utilities/preProcessing/mapFields/mapFields.C
index 9e7b984745e..78645b20b4a 100644
--- a/applications/utilities/preProcessing/mapFields/mapFields.C
+++ b/applications/utilities/preProcessing/mapFields/mapFields.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -286,7 +286,7 @@ int main(int argc, char *argv[])
     fileName rootDirTarget(args.rootPath());
     fileName caseDirTarget(args.globalCaseName());
 
-    fileName casePath = args[1];
+    const auto casePath = args.get<fileName>(1);
     const fileName rootDirSource = casePath.path().toAbsolute();
     const fileName caseDirSource = casePath.name();
 
diff --git a/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C b/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C
index 7c6435f1e42..025c400b267 100644
--- a/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C
+++ b/applications/utilities/preProcessing/mapFieldsPar/mapFieldsPar.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2015-2018 OpenCFD Ltd.
+    Copyright (C) 2015-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
     fileName rootDirTarget(args.rootPath());
     fileName caseDirTarget(args.globalCaseName());
 
-    const fileName casePath = args[1];
+    const auto casePath = args.get<fileName>(1);
     const fileName rootDirSource = casePath.path();
     const fileName caseDirSource = casePath.name();
 
diff --git a/applications/utilities/surface/surfaceAdd/surfaceAdd.C b/applications/utilities/surface/surfaceAdd/surfaceAdd.C
index 6195dd3c687..0db4feefd1f 100644
--- a/applications/utilities/surface/surfaceAdd/surfaceAdd.C
+++ b/applications/utilities/surface/surfaceAdd/surfaceAdd.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -83,9 +83,9 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName inFileName1 = args[1];
-    const fileName inFileName2 = args[2];
-    const fileName outFileName = args[3];
+    const auto inFileName1 = args.get<fileName>(1);
+    const auto inFileName2 = args.get<fileName>(2);
+    const auto outFileName = args.get<fileName>(3);
 
     const bool addPoint     = args.found("points");
     const bool mergeRegions = args.found("mergeRegions");
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
             << nl << endl;
 
         Info<< "Surface  : " << inFileName1<< nl
-            << "Points   : " << args["points"] << nl
+            << "Points   : " << args.get<fileName>("points") << nl
             << "Writing  : " << outFileName << nl << endl;
     }
     else
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
 
     if (addPoint)
     {
-        IFstream pointsFile(args["points"]);
+        IFstream pointsFile(args.get<fileName>("points"));
         const pointField extraPoints(pointsFile);
 
         Info<< "Additional Points:" << extraPoints.size() << endl;
diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C
index 87a04e1e216..4d3b9e39fec 100644
--- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C
+++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -335,7 +335,7 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName surfFileName = args[1];
+    const auto surfFileName = args.get<fileName>(1);
     const bool checkSelfIntersect = args.found("checkSelfIntersection");
     const bool splitNonManifold = args.found("splitNonManifold");
     const label outputThreshold =
diff --git a/applications/utilities/surface/surfaceClean/surfaceClean.C b/applications/utilities/surface/surfaceClean/surfaceClean.C
index 98c850c6950..f1e62642318 100644
--- a/applications/utilities/surface/surfaceClean/surfaceClean.C
+++ b/applications/utilities/surface/surfaceClean/surfaceClean.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2013 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -82,10 +82,10 @@ int main(int argc, char *argv[])
     );
     argList args(argc, argv);
 
-    const fileName inFileName = args[1];
-    const scalar minLen = args.get<scalar>(2);
-    const scalar minQuality = args.get<scalar>(3);
-    const fileName outFileName = args[4];
+    const auto inFileName = args.get<fileName>(1);
+    const auto minLen = args.get<scalar>(2);
+    const auto minQuality = args.get<scalar>(3);
+    const auto outFileName = args.get<fileName>(4);
 
     Info<< "Reading surface " << inFileName << nl
         << "Collapsing all triangles with" << nl
diff --git a/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C b/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C
index 1adad6a7f81..6db75af3df8 100644
--- a/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C
+++ b/applications/utilities/surface/surfaceCoarsen/surfaceCoarsen.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -92,9 +92,9 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName inFileName = args[1];
-    const scalar reduction = args.get<scalar>(2);
-    const fileName outFileName = args[3];
+    const auto inFileName = args.get<fileName>(1);
+    const auto reduction = args.get<scalar>(2);
+    const auto outFileName = args.get<fileName>(3);
 
     if (reduction <= 0 || reduction > 1)
     {
diff --git a/applications/utilities/surface/surfaceConvert/surfaceConvert.C b/applications/utilities/surface/surfaceConvert/surfaceConvert.C
index f65f316f8d2..3530da1ae18 100644
--- a/applications/utilities/surface/surfaceConvert/surfaceConvert.C
+++ b/applications/utilities/surface/surfaceConvert/surfaceConvert.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -159,8 +159,8 @@ int main(int argc, char *argv[])
         }
     }
 
-    const fileName importName(args[1]);
-    const fileName exportName(args[2]);
+    const auto importName = args.get<fileName>(1);
+    const auto exportName = args.get<fileName>(2);
 
     if (importName == exportName)
     {
diff --git a/applications/utilities/surface/surfaceFeatureConvert/surfaceFeatureConvert.C b/applications/utilities/surface/surfaceFeatureConvert/surfaceFeatureConvert.C
index 087b0eed278..03c64a2f390 100644
--- a/applications/utilities/surface/surfaceFeatureConvert/surfaceFeatureConvert.C
+++ b/applications/utilities/surface/surfaceFeatureConvert/surfaceFeatureConvert.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2015 OpenFOAM Foundation
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -106,8 +106,8 @@ int main(int argc, char *argv[])
     argList args(argc, argv);
     Time runTime(args.rootPath(), args.caseName());
 
-    const fileName importName(args[1]);
-    const fileName exportName(args[2]);
+    const auto importName = args.get<fileName>(1);
+    const auto exportName = args.get<fileName>(2);
 
     // Disable inplace editing
     if (importName == exportName)
diff --git a/applications/utilities/surface/surfaceFind/surfaceFind.C b/applications/utilities/surface/surfaceFind/surfaceFind.C
index e23ce768478..1f69a792e69 100644
--- a/applications/utilities/surface/surfaceFind/surfaceFind.C
+++ b/applications/utilities/surface/surfaceFind/surfaceFind.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
 
 
     Info<< "Reading surf ..." << endl;
-    meshedSurface surf1(args[1]);
+    meshedSurface surf1(args.get<fileName>(1));
 
     //
     // Nearest vertex
diff --git a/applications/utilities/surface/surfaceInertia/surfaceInertia.C b/applications/utilities/surface/surfaceInertia/surfaceInertia.C
index 7147ce4656e..2b512097884 100644
--- a/applications/utilities/surface/surfaceInertia/surfaceInertia.C
+++ b/applications/utilities/surface/surfaceInertia/surfaceInertia.C
@@ -6,7 +6,7 @@
     \\/      M anipulation   |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName surfFileName = args[1];
+    const auto surfFileName = args.get<fileName>(1);
     const scalar density = args.getOrDefault<scalar>("density", 1);
 
     vector refPt = Zero;
diff --git a/applications/utilities/surface/surfaceInflate/surfaceInflate.C b/applications/utilities/surface/surfaceInflate/surfaceInflate.C
index 333533f2fa9..a2d52a992d0 100644
--- a/applications/utilities/surface/surfaceInflate/surfaceInflate.C
+++ b/applications/utilities/surface/surfaceInflate/surfaceInflate.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2015 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -609,12 +609,12 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    const word inputName(args[1]);
-    const scalar distance(args.get<scalar>(2));
-    const scalar extendFactor(args.get<scalar>(3));
+    const auto inputName = args.get<word>(1);
+    const auto distance = args.get<scalar>(2);
+    const auto extendFactor = args.get<scalar>(3);
     const bool checkSelfIntersect = args.found("checkSelfIntersection");
-    const label nSmooth = args.getOrDefault<label>("nSmooth", 10);
-    const scalar featureAngle = args.getOrDefault<scalar>("featureAngle", 180);
+    const auto nSmooth = args.getOrDefault<label>("nSmooth", 10);
+    const auto featureAngle = args.getOrDefault<scalar>("featureAngle", 180);
     const bool debug = args.found("debug");
 
 
diff --git a/applications/utilities/surface/surfaceLambdaMuSmooth/surfaceLambdaMuSmooth.C b/applications/utilities/surface/surfaceLambdaMuSmooth/surfaceLambdaMuSmooth.C
index a3b99deebc8..cde4e69ae59 100644
--- a/applications/utilities/surface/surfaceLambdaMuSmooth/surfaceLambdaMuSmooth.C
+++ b/applications/utilities/surface/surfaceLambdaMuSmooth/surfaceLambdaMuSmooth.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2015 OpenCFD Ltd.
+    Copyright (C) 2015-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -156,11 +156,11 @@ int main(int argc, char *argv[])
     );
     argList args(argc, argv);
 
-    const fileName surfFileName = args[1];
-    const scalar lambda = args.get<scalar>(2);
-    const scalar mu = args.get<scalar>(3);
-    const label  iters = args.get<label>(4);
-    const fileName outFileName = args[5];
+    const auto surfFileName = args.get<fileName>(1);
+    const auto lambda = args.get<scalar>(2);
+    const auto mu = args.get<scalar>(3);
+    const auto iters = args.get<label>(4);
+    const auto outFileName = args.get<fileName>(5);
 
     if (lambda < 0 || lambda > 1)
     {
@@ -192,7 +192,7 @@ int main(int argc, char *argv[])
 
     if (args.found("featureFile"))
     {
-        const fileName featureFileName(args["featureFile"]);
+        const auto featureFileName = args.get<fileName>("featureFile");
         Info<< "Reading features from " << featureFileName << " ..." << endl;
 
         edgeMesh feMesh(featureFileName);
diff --git a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C
index b2257f39f1d..53cfa965113 100644
--- a/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C
+++ b/applications/utilities/surface/surfaceMeshConvert/surfaceMeshConvert.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -181,8 +181,8 @@ int main(int argc, char *argv[])
     argList args(argc, argv);
     Time runTime(args.rootPath(), args.caseName());
 
-    const fileName importName(args[1]);
-    const fileName exportName(args[2]);
+    const auto importName = args.get<fileName>(1);
+    const auto exportName = args.get<fileName>(2);
 
     if (importName == exportName)
     {
diff --git a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C
index d80437d35a3..8469ed0b337 100644
--- a/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C
+++ b/applications/utilities/surface/surfaceMeshExport/surfaceMeshExport.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -155,8 +155,8 @@ int main(int argc, char *argv[])
     argList args(argc, argv);
     Time runTime(args.rootPath(), args.caseName());
 
-    const fileName exportName(args[1]);
-    const word importName(args.getOrDefault<word>("name", "default"));
+    const auto exportName = args.get<fileName>(1);
+    const auto importName = args.getOrDefault<word>("name", "default");
 
     const word writeFileType
     (
diff --git a/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C b/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C
index 38b364c949d..25e6bac8a94 100644
--- a/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C
+++ b/applications/utilities/surface/surfaceMeshExtract/surfaceMeshExtract.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2017-2020 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])
     #include "setRootCase.H"
     #include "createTime.H"
 
-    const fileName userOutFileName(args[1]);
+    const auto userOutFileName = args.get<fileName>(1);
 
     if (!userOutFileName.hasExt())
     {
diff --git a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C
index 469c835a6ec..ba7ca665d2a 100644
--- a/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C
+++ b/applications/utilities/surface/surfaceMeshImport/surfaceMeshImport.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2018-2020 OpenCFD Ltd.
+    Copyright (C) 2018-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -167,8 +167,8 @@ int main(int argc, char *argv[])
     }
 
 
-    const fileName importName(args[1]);
-    const word exportName(args.getOrDefault<word>("name", "default"));
+    const auto importName = args.get<fileName>(1);
+    const auto exportName = args.getOrDefault<word>("name", "default");
 
     const word readFileType
     (
diff --git a/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C
index 6409990bfd8..f270125da1b 100644
--- a/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C
+++ b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
     argList args(argc, argv);
     Time runTime(args.rootPath(), args.caseName());
 
-    const fileName importName = args[1];
+    const auto importName = args.get<fileName>(1);
 
     // check that reading is supported
     if (!UnsortedMeshedSurface<face>::canRead(importName, true))
diff --git a/applications/utilities/surface/surfaceOrient/surfaceOrient.C b/applications/utilities/surface/surfaceOrient/surfaceOrient.C
index 4158dc04d95..60750eee296 100644
--- a/applications/utilities/surface/surfaceOrient/surfaceOrient.C
+++ b/applications/utilities/surface/surfaceOrient/surfaceOrient.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2013 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -76,9 +76,9 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName surfFileName = args[1];
-    const point visiblePoint    = args.get<point>(2);
-    const fileName outFileName  = args[3];
+    const auto surfFileName = args.get<fileName>(1);
+    const auto visiblePoint = args.get<point>(2);
+    const auto outFileName  = args.get<fileName>(3);
 
     const bool orientInside = args.found("inside");
     const bool usePierceTest = args.found("usePierceTest");
diff --git a/applications/utilities/surface/surfacePointMerge/surfacePointMerge.C b/applications/utilities/surface/surfacePointMerge/surfacePointMerge.C
index 954a5064d9d..f4057978c0f 100644
--- a/applications/utilities/surface/surfacePointMerge/surfacePointMerge.C
+++ b/applications/utilities/surface/surfacePointMerge/surfacePointMerge.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2013 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -67,9 +67,9 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName surfFileName = args[1];
-    const scalar   mergeTol = args.get<scalar>(2);
-    const fileName outFileName = args[3];
+    const auto surfFileName = args.get<fileName>(1);
+    const auto mergeTol = args.get<scalar>(2);
+    const auto outFileName = args.get<fileName>(3);
 
     const scalar scaling = args.getOrDefault<scalar>("scale", -1);
 
diff --git a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C
index b50d924bd18..72e79526a5d 100644
--- a/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C
+++ b/applications/utilities/surface/surfaceRedistributePar/surfaceRedistributePar.C
@@ -124,8 +124,8 @@ int main(int argc, char *argv[])
     #include "createTime.H"
     runTime.functionObjects().off();
 
-    const fileName surfFileName = args[1];
-    const word distTypeName = args[2];
+    const auto surfFileName = args.get<fileName>(1);
+    const auto distTypeName = args.get<word>(2);
     const label distType =
         distributedTriSurfaceMesh::distributionTypeNames_[distTypeName];
 
diff --git a/applications/utilities/surface/surfaceRefineRedGreen/surfaceRefineRedGreen.C b/applications/utilities/surface/surfaceRefineRedGreen/surfaceRefineRedGreen.C
index b92418e1d43..b1b51f1a19c 100644
--- a/applications/utilities/surface/surfaceRefineRedGreen/surfaceRefineRedGreen.C
+++ b/applications/utilities/surface/surfaceRefineRedGreen/surfaceRefineRedGreen.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2013 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -72,8 +72,8 @@ int main(int argc, char *argv[])
     );
     argList args(argc, argv);
 
-    const fileName surfFileName(args[1]);
-    const fileName outFileName(args[2]);
+    const auto surfFileName = args.get<fileName>(1);
+    const auto outFileName = args.get<fileName>(2);
 
     Info<< "Reading surface from " << surfFileName << " ..." << endl;
 
diff --git a/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C b/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C
index 65649dfd8a5..940c15848f3 100644
--- a/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C
+++ b/applications/utilities/surface/surfaceSplitByPatch/surfaceSplitByPatch.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName surfName = args[1];
+    const auto surfName = args.get<fileName>(1);
 
     const fileName surfBase(surfName.lessExt());
 
diff --git a/applications/utilities/surface/surfaceSplitByTopology/surfaceSplitByTopology.C b/applications/utilities/surface/surfaceSplitByTopology/surfaceSplitByTopology.C
index 7afa04af6cc..66f8b117468 100644
--- a/applications/utilities/surface/surfaceSplitByTopology/surfaceSplitByTopology.C
+++ b/applications/utilities/surface/surfaceSplitByTopology/surfaceSplitByTopology.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -59,12 +60,12 @@ int main(int argc, char *argv[])
     argList::addArgument("output", "The output surface file");
     argList args(argc, argv);
 
-    fileName surfFileName(args[1]);
+    const auto surfFileName = args.get<fileName>(1);
     Info<< "Reading surface from " << surfFileName << endl;
 
-    fileName outFileName(args[2]);
-    fileName outFileBaseName = outFileName.lessExt();
-    word outExtension = outFileName.ext();
+    const auto outFileName = args.get<fileName>(2);
+    const fileName outFileBaseName = outFileName.lessExt();
+    const word outExtension = outFileName.ext();
 
     // Load surface
     triSurface surf(surfFileName);
diff --git a/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C b/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C
index 8c8cd23c8b7..978af67fae7 100644
--- a/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C
+++ b/applications/utilities/surface/surfaceSplitNonManifolds/surfaceSplitNonManifolds.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2019-2020 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -691,8 +691,8 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName inSurfName  = args[1];
-    const fileName outSurfName = args[2];
+    const auto inSurfName  = args.get<fileName>(1);
+    const auto outSurfName = args.get<fileName>(2);
     const bool debug = args.found("debug");
 
     Info<< "Reading surface from " << inSurfName << endl;
diff --git a/applications/utilities/surface/surfaceSubset/surfaceSubset.C b/applications/utilities/surface/surfaceSubset/surfaceSubset.C
index 04031d3f046..0f7b60e154f 100644
--- a/applications/utilities/surface/surfaceSubset/surfaceSubset.C
+++ b/applications/utilities/surface/surfaceSubset/surfaceSubset.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -67,15 +67,13 @@ int main(int argc, char *argv[])
     argList args(argc, argv);
 
     Info<< "Reading dictionary " << args[1] << " ..." << endl;
-    IFstream dictFile(args[1]);
+    IFstream dictFile(args.get<fileName>(1));
     dictionary meshSubsetDict(dictFile);
 
     Info<< "Reading surface " << args[2] << " ..." << endl;
+    meshedSurface surf1(args.get<fileName>(2));
 
-    meshedSurface surf1(args[2]);
-
-    const fileName outFileName(args[3]);
-
+    const auto outFileName(args.get<fileName>(3));
 
     Info<< "Original:" << endl;
     surf1.writeStats(Info);
@@ -217,7 +215,7 @@ int main(int argc, char *argv[])
     {
         const dictionary& surfDict = meshSubsetDict.subDict("surface");
 
-        const fileName surfName(surfDict.get<fileName>("name"));
+        const auto surfName(surfDict.get<fileName>("name"));
 
         const volumeType::type volType =
         (
diff --git a/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C b/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C
index 8a78994144f..d4d31c1ca76 100644
--- a/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C
+++ b/applications/utilities/surface/surfaceToPatch/surfaceToPatch.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -196,7 +196,7 @@ int main(int argc, char *argv[])
     #include "createTime.H"
     #include "createPolyMesh.H"
 
-    const fileName surfName = args[1];
+    const auto surfName = args.get<fileName>(1);
 
     Info<< "Reading surface from " << surfName << " ..." << endl;
 
diff --git a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C
index 85948f878d6..4322a0a530c 100644
--- a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C
+++ b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2017-2020 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -283,8 +283,8 @@ int main(int argc, char *argv[])
         }
     }
 
-    const fileName importName(args[1]);
-    const fileName exportName(args[2]);
+    const auto importName = args.get<fileName>(1);
+    const auto exportName = args.get<fileName>(2);
 
     const word readFileType
     (
diff --git a/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C b/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C
index 780d4eb6c15..220a0da6ddb 100644
--- a/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C
+++ b/applications/utilities/thermophysical/adiabaticFlameT/adiabaticFlameT.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -70,7 +71,7 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName controlFileName = args[1];
+    const auto controlFileName = args.get<fileName>(1);
 
     // Construct control dictionary
     IFstream controlFile(controlFileName);
diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C
index 2508069f393..e248c45c979 100644
--- a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C
+++ b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -76,11 +77,18 @@ int main(int argc, char *argv[])
 
     speciesTable species;
 
-    chemkinReader cr(species, args[1], args[3], args[2], newFormat);
+    chemkinReader cr
+    (
+        species,
+        args.get<fileName>(1),  // chemkin fileName
+        args.get<fileName>(3),  // thermo fileName
+        args.get<fileName>(2),  // transport fileName
+        newFormat
+    );
 
     {
         // output: reactions file
-        OFstream reactionsFile(args[4]);
+        OFstream reactionsFile(args.get<fileName>(4));
 
         reactionsFile.writeEntry("elements", cr.elementNames()) << nl;
         reactionsFile.writeEntry("species", cr.species()) << nl;
@@ -113,7 +121,7 @@ int main(int argc, char *argv[])
 
     // output: thermo file
 
-    thermoDict.write(OFstream(args[5])(), false);
+    thermoDict.write(OFstream(args.get<fileName>(5))(), false);
 
 
     Info<< "End\n" << endl;
diff --git a/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C b/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C
index 8cdbe5060e1..a6f2e4fb63f 100644
--- a/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C
+++ b/applications/utilities/thermophysical/equilibriumFlameT/equilibriumFlameT.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -73,7 +74,7 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName controlFileName = args[1];
+    const auto controlFileName = args.get<fileName>(1);
 
     // Construct control dictionary
     IFstream controlFile(controlFileName);
diff --git a/applications/utilities/thermophysical/mixtureAdiabaticFlameT/mixtureAdiabaticFlameT.C b/applications/utilities/thermophysical/mixtureAdiabaticFlameT/mixtureAdiabaticFlameT.C
index 5d2c3386863..c0580d03b9a 100644
--- a/applications/utilities/thermophysical/mixtureAdiabaticFlameT/mixtureAdiabaticFlameT.C
+++ b/applications/utilities/thermophysical/mixtureAdiabaticFlameT/mixtureAdiabaticFlameT.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
+    Copyright (C) 2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -69,7 +70,7 @@ int main(int argc, char *argv[])
 
     argList args(argc, argv);
 
-    const fileName controlFileName(args[1]);
+    const auto controlFileName = args.get<fileName>(1);
 
     // Construct control dictionary
     IFstream controlFile(controlFileName);
diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C
index 66f39bded28..cd478fea969 100644
--- a/src/OpenFOAM/db/IOobject/IOobject.C
+++ b/src/OpenFOAM/db/IOobject/IOobject.C
@@ -154,8 +154,8 @@ bool Foam::IOobject::fileNameComponents
     // Convert explicit relative file-system path to absolute file-system path.
     if (path.starts_with("./") || path.starts_with("../"))
     {
-        fileName absPath = cwd()/path;
-        absPath.clean();
+        fileName absPath(cwd()/path);
+        absPath.clean();  // Remove unneeded ".."
 
         return fileNameComponents(absPath, instance, local, name);
     }
diff --git a/src/OpenFOAM/db/dictionary/dictionarySearch.C b/src/OpenFOAM/db/dictionary/dictionarySearch.C
index 7b7a9e65cbe..401c7825d7a 100644
--- a/src/OpenFOAM/db/dictionary/dictionarySearch.C
+++ b/src/OpenFOAM/db/dictionary/dictionarySearch.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2017-2019 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -184,7 +184,7 @@ Foam::dictionary::const_searcher Foam::dictionary::csearchSlashScoped
     }
     else if (slash == 0)
     {
-        // (isAbsolute)
+        // isAbsolute:
         // Ascend to top-level
         while (&dictPtr->parent_ != &dictionary::null)
         {
@@ -385,8 +385,9 @@ const Foam::dictionary* Foam::dictionary::cfindScopedDict
     }
 
     const dictionary* dictPtr = this;
-    if (fileName::isAbsolute(dictPath))
+    if (dictPath[0] == '/')
     {
+        // isAbsolute:
         // Ascend to top-level
         while (&dictPtr->parent_ != &dictionary::null)
         {
@@ -394,10 +395,11 @@ const Foam::dictionary* Foam::dictionary::cfindScopedDict
         }
     }
 
-    fileName path = dictPath.clean();
-    const wordList cmpts = path.components();
+    fileName path(dictPath); // Work on copy
+    path.clean();  // Remove unneeded ".."
+    const wordList dictCmpts(path.components()); // Split on '/'
 
-    for (const word& cmpt : cmpts)
+    for (const word& cmpt : dictCmpts)
     {
         if (cmpt == ".")
         {
@@ -486,8 +488,9 @@ Foam::dictionary* Foam::dictionary::makeScopedDict(const fileName& dictPath)
     }
 
     dictionary* dictPtr = this;
-    if (fileName::isAbsolute(dictPath))
+    if (dictPath[0] == '/')
     {
+        // isAbsolute:
         // Ascend to top-level
         while (&dictPtr->parent_ != &dictionary::null)
         {
@@ -495,14 +498,11 @@ Foam::dictionary* Foam::dictionary::makeScopedDict(const fileName& dictPath)
         }
     }
 
-    // Work on a copy, without any assumptions
-    std::string path = dictPath;
-    fileName::clean(path);
+    std::string path(dictPath); // Work on a copy
+    fileName::clean(path);  // Remove unneeded ".."
+    auto dictCmpts = stringOps::split(path, '/'); // Split on '/'
 
-    // Split on '/'
-    auto cmpts = stringOps::split(path, '/');
-
-    for (const auto& cmpt : cmpts)
+    for (const auto& cmpt : dictCmpts)
     {
         if (cmpt == ".")
         {
diff --git a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C
index 36cb7cdd0a5..51be217fda8 100644
--- a/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C
+++ b/src/OpenFOAM/db/functionObjects/writeFile/writeFile.C
@@ -52,7 +52,7 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
     // Put in undecomposed case
     // (Note: gives problems for distributed data running)
 
-    fileName baseDir =
+    fileName baseDir
     (
         fileObr_.time().globalPath()
       / functionObject::outputPrefix
@@ -67,7 +67,6 @@ Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
             baseDir /= mesh.name();
         }
     }
-
     baseDir.clean();  // Remove unneeded ".."
 
     return baseDir;
diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C
index fc62b4bd044..4f4f957e441 100644
--- a/src/OpenFOAM/global/argList/argList.C
+++ b/src/OpenFOAM/global/argList/argList.C
@@ -715,8 +715,7 @@ void Foam::argList::setCasePaths()
 
     if (optIter.found())
     {
-        caseDir = fileName::validate(optIter.val());
-        caseDir.clean();
+        caseDir = fileName::validate(optIter.val());  // includes 'clean'
 
         if (caseDir.empty() || caseDir == ".")
         {
@@ -1193,7 +1192,7 @@ void Foam::argList::parse
                 // Could also check for absolute path, but shouldn't be needed
                 if (adjustOpt)
                 {
-                    source.clean();
+                    source.clean();  // Remove unneeded ".."
                     options_.set("decomposeParDict", source);
                 }
             }
diff --git a/src/OpenFOAM/global/argList/argList.H b/src/OpenFOAM/global/argList/argList.H
index 75ffd9dbef4..e9d022b5455 100644
--- a/src/OpenFOAM/global/argList/argList.H
+++ b/src/OpenFOAM/global/argList/argList.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -378,6 +378,7 @@ public:
 
         //- Get a value from the argument at index.
         //  Index 1 is the first (non-option) argument.
+        //  For fileName type, invokes fileName::validate()
         template<class T>
         inline T get(const label index) const;
 
@@ -388,6 +389,7 @@ public:
 
         //- Get a value from the named option
         //  The default template parameter is string (ie, no conversion).
+        //  For fileName type, invokes fileName::validate()
         template<class T=string>
         inline T get(const word& optName) const;
 
diff --git a/src/OpenFOAM/global/argList/argListI.H b/src/OpenFOAM/global/argList/argListI.H
index ed6f1fe59c5..83344cdf2d9 100644
--- a/src/OpenFOAM/global/argList/argListI.H
+++ b/src/OpenFOAM/global/argList/argListI.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2013 OpenFOAM Foundation
-    Copyright (C) 2017-2020 OpenCFD Ltd.
+    Copyright (C) 2017-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -221,7 +221,7 @@ namespace Foam
     template<>
     inline fileName argList::get<Foam::fileName>(const label index) const
     {
-        return args_[index];
+        return fileName::validate(args_[index]);
     }
 
 
@@ -240,7 +240,7 @@ namespace Foam
     template<>
     inline fileName argList::get<Foam::fileName>(const word& optName) const
     {
-        return options_[optName];
+        return fileName::validate(options_[optName]);
     }
 }
 
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C
index 2905d6fbc28..09ebe26f3a9 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileName.C
+++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2016-2019 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -52,72 +52,164 @@ int Foam::fileName::allowSpaceInFileName
 const Foam::fileName Foam::fileName::null;
 
 
-// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
 
-Foam::fileName Foam::fileName::validate
+namespace
+{
+
+// doClean:
+//   - remove duplicate slashes, "/./" and "/../" components.
+//
+// checkValid:
+//   - similar to stripInvalid (but silent)
+//
+// return True if the content changed
+static bool cleanFileName
 (
-    const std::string& s,
-    const bool doClean
+    std::string& str,
+    const bool doClean,
+    const bool checkValid
 )
 {
-    // The logic is very similar to stripInvalid,
-    // but silently removes bad characters
-
-    fileName out;
-    out.resize(s.length());
-
-    std::string::size_type len = 0;
-
-    auto iter = s.cbegin();
+    const auto maxLen = str.length();
+    std::string::size_type nChar = 0;
 
-    #ifdef _WIN32
-    // Preserve UNC \\server-name\...
-    if (s.length() > 2 && s[0] == '\\' && s[1] == '\\')
+    // Preserve UNC \\server\path (windows)
+    // - MS-windows only, but handle for other systems
+    //   since there is no collision with this pattern
+    if (maxLen > 2 && str[0] == '\\' && str[1] == '\\')
     {
-        len += 2;
-        ++iter;
-        ++iter;
+        nChar += 2;
     }
-    #endif
 
     char prev = 0;
-    for (/*nil*/; iter != s.cend(); ++iter)
-    {
-        char c = *iter;
+    auto top = std::string::npos;  // Not yet found
+    bool changed = false;
 
-        // Treat raw backslash like a path separator. There is no "normal"
-        // way for these to be there (except for an OS that uses them), but
-        // could also cause issues when writing strings, shell commands etc.
+    for (auto src = nChar; src < maxLen; /*nil*/)
+    {
+        char c = str[src++];
 
+        // Treat raw backslash like a path separator.
+        // There is no "normal" way for these to be there
+        // (except for an OS that uses them), but can cause issues
+        // when writing strings, shell commands etc.
         if (c == '\\')
         {
             c = '/';
+            str[nChar] = c;
+            changed = true;
+        }
+        else if (checkValid && !Foam::fileName::valid(c))
+        {
+            // Ignore invalid chars
+            // Could explicitly allow space character or rely on
+            // allowSpaceInFileName via fileName::valid()
+            continue;
         }
 
-        // Could explicitly allow space character or rely on
-        // allowSpaceInFileName via fileName::valid()
+        if (c == '/' && top == std::string::npos)
+        {
+            // Top-level slash not previously determined
+            top = (src-1);
+        }
 
-        if (fileName::valid(c))
+        if (doClean && prev == '/')
         {
-            if (doClean && prev == '/' && c == '/')
+            // Repeated '/' - skip it
+            if (c == '/')
             {
-                // Avoid repeated '/';
                 continue;
             }
 
-            // Only track valid chars
-            out[len++] = prev = c;
+            // Could be "/./", "/../" or a trailing "/."
+            if (c == '.')
+            {
+                // Trailing "/." - skip it
+                if (src >= maxLen)
+                {
+                    break;
+                }
+
+                // Peek at the next character
+                const char c1 = str[src];
+
+                // Found "/./" - skip over it
+                if (c1 == '/' || c1 == '\\')
+                {
+                    ++src;
+                    continue;
+                }
+
+                // Trailing "/.." or intermediate "/../"
+                if
+                (
+                    c1 == '.'
+                 &&
+                    (
+                        src+1 >= maxLen
+                     || str[src+1] == '/' || str[src+1] == '\\'
+                    )
+                )
+                {
+                    // Backtrack to find the parent directory
+                    // Minimum of 3 characters:  '/x/../'
+                    // Strip it, provided it is above the top point
+
+                    std::string::size_type parent;
+                    if
+                    (
+                        nChar > 2
+                     && top != std::string::npos
+                     && (parent = str.rfind('/', nChar-2)) != std::string::npos
+                     && parent >= top
+                    )
+                    {
+                        nChar = parent + 1;   // Retain '/' from the parent
+                        src += 2;
+                        continue;
+                    }
+
+                    // Bad resolution, eg 'abc/../../'
+                    // Retain the sequence, but move the top to avoid it being
+                    // considered a valid parent later
+                    top = nChar + 2;
+                }
+            }
         }
+
+        str[nChar++] = prev = c;
     }
 
-    if (doClean && prev == '/' && len > 1)
+    // Remove trailing '/'
+    if (doClean && nChar > 1 && str[nChar-1] == '/')
     {
-        // Avoid trailing '/'
-        --len;
+        --nChar;
     }
 
-    out.resize(len);
+    str.erase(nChar);
+    return changed || (nChar != maxLen);
+}
+
+} // End namespace Foam
 
+
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+bool Foam::fileName::clean(std::string& str)
+{
+    return cleanFileName(str, true, false);  // clean, checkValid = false
+}
+
+
+Foam::fileName Foam::fileName::validate
+(
+    const std::string& str,
+    const bool doClean
+)
+{
+    fileName out(str, false);           // copy, no stripping
+    cleanFileName(out, doClean, true);  // checkValid = true
     return out;
 }
 
@@ -288,117 +380,19 @@ Foam::fileName& Foam::fileName::toAbsolute()
     {
         fileName& f = *this;
         f = cwd()/f;
-        f.clean();
+        f.clean();  // Remove unneeded ".."
     }
 
     return *this;
 }
 
 
-bool Foam::fileName::clean(std::string& str)
-{
-    // Start with the top slash found - we are never allowed to go above it
-    char prev = '/';
-    auto top = str.find(prev);
-
-    // No slashes - nothing to do
-    if (top == std::string::npos)
-    {
-        return false;
-    }
-
-    // Number of output characters
-    auto nChar = top+1;
-
-    const auto maxLen = str.length();
-
-    for (auto src = nChar; src < maxLen; /*nil*/)
-    {
-        const char c = str[src++];
-
-        if (prev == '/')
-        {
-            // Repeated '/' - skip it
-            if (c == '/')
-            {
-                continue;
-            }
-
-            // Could be "/./", "/../" or a trailing "/."
-            if (c == '.')
-            {
-                // Trailing "/." - skip it
-                if (src >= maxLen)
-                {
-                    break;
-                }
-
-                // Peek at the next character
-                const char c1 = str[src];
-
-                // Found "/./" - skip it
-                if (c1 == '/')
-                {
-                    ++src;
-                    continue;
-                }
-
-                // Trailing "/.." or intermediate "/../"
-                if (c1 == '.' && (src+1 >= maxLen || str[src+1] == '/'))
-                {
-                    string::size_type parent;
-
-                    // Backtrack to find the parent directory
-                    // Minimum of 3 characters:  '/x/../'
-                    // Strip it, provided it is above the top point
-                    if
-                    (
-                        nChar > 2
-                     && (parent = str.rfind('/', nChar-2)) != string::npos
-                     && parent >= top
-                    )
-                    {
-                        nChar = parent + 1;   // Retain '/' from the parent
-                        src += 2;
-                        continue;
-                    }
-
-                    // Bad resolution, eg 'abc/../../'
-                    // Retain the sequence, but move the top to avoid it being
-                    // considered a valid parent later
-                    top = nChar + 2;
-                }
-            }
-        }
-        str[nChar++] = prev = c;
-    }
-
-    // Remove trailing slash
-    if (nChar > 1 && str[nChar-1] == '/')
-    {
-        nChar--;
-    }
-
-    str.resize(nChar);
-
-    return (nChar != maxLen);
-}
-
-
 bool Foam::fileName::clean()
 {
     return fileName::clean(*this);
 }
 
 
-Foam::fileName Foam::fileName::clean() const
-{
-    fileName cleaned(*this);
-    fileName::clean(cleaned);
-    return cleaned;
-}
-
-
 std::string Foam::fileName::nameLessExt(const std::string& str)
 {
     auto beg = str.rfind('/');
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H
index 78f851d2a7c..b00c78e8049 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileName.H
+++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H
@@ -151,10 +151,10 @@ public:
         //- Is this character valid for a fileName?
         inline static bool valid(char c);
 
-        //- Construct fileName with no invalid characters, possibly applying
+        //- Construct fileName without invalid characters, possibly applying
         //- other transformations such as changing the path separator,
         //- removing duplicate or trailing slashes, etc.
-        static fileName validate(const std::string& s, const bool doClean=true);
+        static fileName validate(const std::string&, const bool doClean=true);
 
         //- Join two strings with a path separator ('/' by default).
         //  No separator is added if either argument is an empty string or
@@ -174,44 +174,48 @@ public:
         //- Strip invalid characters
         inline void stripInvalid();
 
-        //- Cleanup filename
+        //- Cleanup filename string, possibly applies other transformations
+        //- such as changing the path separator etc.
         //
-        // Removes trailing \c /
-        //   \verbatim
-        //       /                 -->   /
-        //       /abc/             -->   /abc
-        //   \endverbatim
+        // Changes back-slash to forward-slash path separator,
+        // while preserving windows UNC:
+        // \verbatim
+        //     \\server\abc\def  -->   \\server/abc/def
+        // \endverbatim
         //
-        // Removes repeated slashes
-        //   \verbatim
-        //       /abc////def        -->   /abc/def
-        //   \endverbatim
+        // Removes trailing slash:
+        // \verbatim
+        //     /                 -->   /
+        //     /abc/             -->   /abc
+        // \endverbatim
         //
-        // Removes \c /./ (current directory)
-        //   \verbatim
-        //       /abc/def/./ghi/.   -->   /abc/def/ghi
-        //       abc/def/./         -->   abc/def
-        //       ./abc/             -->   ./abc
-        //   \endverbatim
+        // Removes repeated slashes, but preserves UNC:
+        // \verbatim
+        //     /abc////def          -->   /abc/def
+        //     \\server\abc////def  -->   \\server/abc/def
+        // \endverbatim
         //
-        // Removes \c /../ (parent directory)
-        //   \verbatim
-        //       /abc/def/../ghi/jkl/nmo/..   -->   /abc/ghi/jkl
-        //       abc/../def/ghi/../jkl        -->   abc/../def/jkl
-        //   \endverbatim
+        // Removes \c "/./" (current directory), except for leading one:
+        // \verbatim
+        //     /abc/def/./ghi/.   -->   /abc/def/ghi
+        //     abc/def/./         -->   abc/def
+        //     ./abc/             -->   ./abc
+        // \endverbatim
+        //
+        // Removes \c "/../" (parent directory), except for leading one:
+        // \verbatim
+        //     /abc/def/../ghi/jkl/nmo/..   -->   /abc/ghi/jkl
+        //     abc/../def/ghi/../jkl        -->   abc/../def/jkl
+        // \endverbatim
+        // .
         //
         // \return True if the content changed
         static bool clean(std::string& str);
 
-
-        //- Cleanup filename inplace
-        //  \return True if any contents changed
+        //- Cleanup filename (inplace)
+        //  \return True if the content changed
         bool clean();
 
-        //- Cleanup filename
-        //  \return cleaned copy of fileName
-        fileName clean() const;
-
 
     // Interrogation
 
@@ -223,10 +227,13 @@ public:
         //  \param checkGzip add an additional test for a gzip FILE
         Type type(bool followLink=true, bool checkGzip=false) const;
 
-        //- Return true if string starts with a '/'
+        //- Return true if filename starts with a '/' or '\\'
+        //- or (windows-only) with a filesystem-root
         inline static bool isAbsolute(const std::string& str);
 
-        //- Return true if file name is absolute (starts with a '/')
+        //- Return true if filename is absolute,
+        //- which means it starts with a '/' or '\\'
+        //- or (windows-only) with a filesystem-root
         inline bool isAbsolute() const;
 
         //- Convert from relative to absolute
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
index f7fffcbc7e2..ed1e860e455 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
+++ b/src/OpenFOAM/primitives/strings/fileName/fileNameI.H
@@ -135,20 +135,22 @@ inline void Foam::fileName::stripInvalid()
 
 inline bool Foam::fileName::isAbsolute(const std::string& str)
 {
-    return
+    return !str.empty() &&
     (
-        (!str.empty() && str.front() == '/')  // ie, str.starts_with('/')
-        #ifdef _WIN32
-        ||
-        (
-            // Eg, d:/path or \\machine/path
-            (str.length() > 2) &&
-            (
-                (str[1] == ':'  && str[2] == '/')
-             || (str[0] == '\\' && str[1] == '\\')
-            )
+        // Starts with '/', but also accept '\\' since it will be
+        // converted to a generic '/' or it is part of a (windows)
+        // UNC '\\server-name\path'
+        // - accept even on non-windows systems
+
+        (str[0] == '/' || str[0] == '\\')
+
+#ifdef _WIN32
+         // Filesytem root - eg, d:/path or d:\path
+     || (
+            (str.length() > 2 && str[1] == ':')
+         && (str[2] == '/' || str[2] == '\\')
         )
-        #endif
+#endif
     );
 }
 
diff --git a/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C b/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C
index 3aa139bb876..30fc454607f 100644
--- a/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C
+++ b/src/finiteVolume/fvMesh/fvGeometryScheme/averageNeighbour/averageNeighbourFvGeometryScheme.C
@@ -699,13 +699,13 @@ void Foam::averageNeighbourFvGeometryScheme::movePoints()
 
 
             // Write current non-ortho
-            fileName outputDir =
+            fileName outputDir
             (
                 mesh_.time().globalPath()
               / functionObject::outputPrefix
               / mesh_.pointsInstance()
             );
-            outputDir.clean();
+            outputDir.clean();  // Remove unneeded ".."
             writerPtr = surfaceWriter::New
             (
                 "ensight" //"vtk"
diff --git a/src/functionObjects/field/externalCoupled/externalCoupled.C b/src/functionObjects/field/externalCoupled/externalCoupled.C
index 3760669f01f..18706366ebb 100644
--- a/src/functionObjects/field/externalCoupled/externalCoupled.C
+++ b/src/functionObjects/field/externalCoupled/externalCoupled.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2015-2020 OpenCFD Ltd.
+    Copyright (C) 2015-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -90,10 +90,10 @@ Foam::fileName Foam::functionObjects::externalCoupled::groupDir
     fileName result
     (
         commsDir
-       /regionGroupName
-       /string::validate<fileName>(groupName)
+      / regionGroupName
+      / word::validate(groupName)
     );
-    result.clean();
+    result.clean();  // Remove unneeded ".."
 
     return result;
 }
diff --git a/src/functionObjects/lagrangian/dataCloud/dataCloud.C b/src/functionObjects/lagrangian/dataCloud/dataCloud.C
index 1c91d52f3ae..c7ec4df888a 100644
--- a/src/functionObjects/lagrangian/dataCloud/dataCloud.C
+++ b/src/functionObjects/lagrangian/dataCloud/dataCloud.C
@@ -195,7 +195,7 @@ bool Foam::functionObjects::dataCloud::read(const dictionary& dict)
         // Standard postProcessing/ naming
         directory_ = time_.globalPath()/functionObject::outputPrefix/name();
     }
-    directory_.clean();
+    directory_.clean();  // Remove unneeded ".."
 
     return true;
 }
diff --git a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C
index deba0c5e5fc..b56c72db3c1 100644
--- a/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C
+++ b/src/functionObjects/lagrangian/vtkCloud/vtkCloud.C
@@ -449,7 +449,7 @@ bool Foam::functionObjects::vtkCloud::read(const dictionary& dict)
         // Standard postProcessing/ naming
         directory_ = time_.globalPath()/functionObject::outputPrefix/name();
     }
-    directory_.clean();
+    directory_.clean();  // Remove unneeded ".."
 
     return true;
 }
diff --git a/src/functionObjects/utilities/abort/abort.C b/src/functionObjects/utilities/abort/abort.C
index 7f0a5603888..c8a8e0d531d 100644
--- a/src/functionObjects/utilities/abort/abort.C
+++ b/src/functionObjects/utilities/abort/abort.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2016-2020 OpenCFD Ltd.
+    Copyright (C) 2016-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -167,11 +167,10 @@ bool Foam::functionObjects::abort::read(const dictionary& dict)
     if (dict.readIfPresent("file", file_))
     {
         file_.expand();
-
-        if (!file_.isAbsolute() && file_.size())
+        if (!file_.empty() && !file_.isAbsolute())
         {
             file_ = time_.globalPath()/file_;
-            file_.clean();
+            file_.clean();  // Remove unneeded ".."
         }
     }
 
@@ -179,7 +178,7 @@ bool Foam::functionObjects::abort::read(const dictionary& dict)
     if (file_.empty())
     {
         file_ = time_.globalPath()/name();
-        file_.clean();
+        file_.clean();  // Remove unneeded ".."
     }
 
     triggered_ = false;
diff --git a/src/functionObjects/utilities/ensightWrite/ensightWrite.C b/src/functionObjects/utilities/ensightWrite/ensightWrite.C
index 7131e34fc6b..36a3b53d185 100644
--- a/src/functionObjects/utilities/ensightWrite/ensightWrite.C
+++ b/src/functionObjects/utilities/ensightWrite/ensightWrite.C
@@ -175,7 +175,7 @@ bool Foam::functionObjects::ensightWrite::read(const dictionary& dict)
         // Standard postProcessing/ naming
         outputDir_ = time_.globalPath()/functionObject::outputPrefix/name();
     }
-    outputDir_.clean();
+    outputDir_.clean();  // Remove unneeded ".."
 
     return true;
 }
diff --git a/src/functionObjects/utilities/vtkWrite/vtkWrite.C b/src/functionObjects/utilities/vtkWrite/vtkWrite.C
index 7e0ca767ace..851f4a99f47 100644
--- a/src/functionObjects/utilities/vtkWrite/vtkWrite.C
+++ b/src/functionObjects/utilities/vtkWrite/vtkWrite.C
@@ -236,7 +236,7 @@ bool Foam::functionObjects::vtkWrite::read(const dictionary& dict)
         // Standard postProcessing/ naming
         outputDir_ = time_.globalPath()/functionObject::outputPrefix/name();
     }
-    outputDir_.clean();
+    outputDir_.clean();  // Remove unneeded ".."
 
     return true;
 }
diff --git a/src/fvOptions/sources/derived/rotorDiskSource/bladeModel/bladeModel.C b/src/fvOptions/sources/derived/rotorDiskSource/bladeModel/bladeModel.C
index 7e4ea215fbf..08932924805 100644
--- a/src/fvOptions/sources/derived/rotorDiskSource/bladeModel/bladeModel.C
+++ b/src/fvOptions/sources/derived/rotorDiskSource/bladeModel/bladeModel.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2020 OpenCFD Ltd.
+    Copyright (C) 2020-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -36,7 +36,7 @@ License
 
 bool Foam::bladeModel::readFromFile() const
 {
-    return fName_ != fileName::null;
+    return !fName_.empty();
 }
 
 
@@ -96,7 +96,7 @@ Foam::bladeModel::bladeModel(const dictionary& dict)
     radius_(),
     twist_(),
     chord_(),
-    fName_(fileName::null)
+    fName_()
 {
     List<Tuple2<word, vector>> data;
     if (readFromFile())
diff --git a/src/fvOptions/sources/derived/rotorDiskSource/profileModel/profileModel.C b/src/fvOptions/sources/derived/rotorDiskSource/profileModel/profileModel.C
index b47afe831f0..41de57780e3 100644
--- a/src/fvOptions/sources/derived/rotorDiskSource/profileModel/profileModel.C
+++ b/src/fvOptions/sources/derived/rotorDiskSource/profileModel/profileModel.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2017 OpenFOAM Foundation
-    Copyright (C) 2019-2020 OpenCFD Ltd.
+    Copyright (C) 2019-2021 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -42,7 +42,7 @@ namespace Foam
 
 bool Foam::profileModel::readFromFile() const
 {
-    return fName_ != fileName::null;
+    return !fName_.empty();
 }
 
 
diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
index e8ef067ef1f..5be91fd952c 100644
--- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
+++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
@@ -2559,10 +2559,12 @@ Foam::label Foam::meshRefinement::findRegions
                 if (Pstream::master())
                 {
                     outputDir =
+                    (
                         mesh.time().globalPath()
                       / functionObject::outputPrefix
-                      / mesh.pointsInstance();
-                    outputDir.clean();
+                      / mesh.pointsInstance()
+                    );
+                    outputDir.clean();  // Remove unneeded ".."
                     mkDir(outputDir);
                 }
 
diff --git a/src/meshTools/coupling/externalFileCoupler.C b/src/meshTools/coupling/externalFileCoupler.C
index 0cae8f6dcd3..722322dc149 100644
--- a/src/meshTools/coupling/externalFileCoupler.C
+++ b/src/meshTools/coupling/externalFileCoupler.C
@@ -103,7 +103,7 @@ Foam::externalFileCoupler::externalFileCoupler()
     log(false)
 {
     commsDir_.expand();
-    commsDir_.clean();
+    commsDir_.clean();  // Remove unneeded ".."
 }
 
 
@@ -118,7 +118,7 @@ Foam::externalFileCoupler::externalFileCoupler(const fileName& commsDir)
     log(false)
 {
     commsDir_.expand();
-    commsDir_.clean();
+    commsDir_.clean();  // Remove unneeded ".."
 
     if (Pstream::master())
     {
@@ -158,7 +158,7 @@ bool Foam::externalFileCoupler::readDict(const dictionary& dict)
     {
         dict.readEntry("commsDir", commsDir_);
         commsDir_.expand();
-        commsDir_.clean();
+        commsDir_.clean();  // Remove unneeded ".."
         statusDone_ = dict.getOrDefault<word>("statusDone", "done");
         slaveFirst_ = dict.getOrDefault("initByExternal", false);
 
diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C
index 626341fcd58..53baa172944 100644
--- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C
+++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C
@@ -1760,14 +1760,15 @@ Foam::pointIndexHit Foam::mappedPatchBase::facePoint
 const Foam::objectRegistry& Foam::mappedPatchBase::subRegistry
 (
     const objectRegistry& obr,
-    const fileName& rawFName
+    const fileName& path
 )
 {
-    // Lookup (and create if non existing) a registry using a '/' separated
-    // path.
+    // Lookup (and create if non-existing) a registry using
+    // '/' separated path. Like 'mkdir -p'
 
-    const fileName fName(rawFName.clean());
-    const wordList names(fName.components());
+    fileName cleanedPath(path);
+    cleanedPath.clean();  // Remove unneeded ".."
+    const wordList names(cleanedPath.components());
 
     if (names.empty())
     {
diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C
index bce791da89a..63b0222af6e 100644
--- a/src/sampling/probes/probes.C
+++ b/src/sampling/probes/probes.C
@@ -208,14 +208,13 @@ Foam::label Foam::probes::prepare()
         // Put in undecomposed case
         // (Note: gives problems for distributed data running)
 
-        fileName probeDir =
+        fileName probeDir
         (
             mesh_.time().globalPath()
           / functionObject::outputPrefix
           / probeSubDir
           / mesh_.time().timeName()
         );
-
         probeDir.clean();  // Remove unneeded ".."
 
         // ignore known fields, close streams for fields that no longer exist
diff --git a/src/sampling/sampledSet/shortestPath/shortestPathSet.C b/src/sampling/sampledSet/shortestPath/shortestPathSet.C
index cd5f1c85f7b..32ae511e8b6 100644
--- a/src/sampling/sampledSet/shortestPath/shortestPathSet.C
+++ b/src/sampling/sampledSet/shortestPath/shortestPathSet.C
@@ -1316,13 +1316,13 @@ Foam::shortestPathSet::shortestPathSet
 {
     if (debug)
     {
-        fileName outputDir =
+        fileName outputDir
         (
             mesh.time().globalPath()
           / functionObject::outputPrefix
           / mesh.pointsInstance()
         );
-        outputDir.clean();
+        outputDir.clean();  // Remove unneeded ".."
 
         Info<< "shortestPathSet : Writing blocked faces to "
             << outputDir << endl;
diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C
index df310b37cd3..3605b16296e 100644
--- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C
+++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C
@@ -871,7 +871,7 @@ Foam::chemkinReader::chemkinReader
     fileName chemkinFile(thermoDict.get<fileName>("CHEMKINFile"));
     chemkinFile.expand();
 
-    fileName thermoFile = fileName::null;
+    fileName thermoFile;
     thermoDict.readIfPresent("CHEMKINThermoFile", thermoFile);
     thermoFile.expand();
 
@@ -887,7 +887,7 @@ Foam::chemkinReader::chemkinReader
             chemkinFile = relPath/chemkinFile;
         }
 
-        if (thermoFile != fileName::null && !thermoFile.isAbsolute())
+        if (!thermoFile.empty() && !thermoFile.isAbsolute())
         {
             thermoFile = relPath/thermoFile;
         }
-- 
GitLab