<# FPS:Containers:Common:Public:Mount-Path:ACTIVE #>

 

function Mount-Path {

 

<#

.DESCRIPTION

Module: Common

Public CmdLet: Mount-Path

 

Ensures that a complete path exists from the path sent as a parameter.  Interrogates the entire stream to make sure all sub-paths

exist prior to checking the next.  At the conclusion of the CmdLet, the complete path will exist and the return path will be the

fully qualified path that was created.  This is a KEY foundational CmdLet and is loaded perpetually via Pro-Config.ps1

 

.EXAMPLE

 

if (Push-NeededFor Mount-Path) { . (Get-ActiveFileNm -PS1 Mount-Path) }

$Path = Mount-Path ("D:\FPS\Media\Scratch\Mount-Path")

 

.CC

 

[2024.11.08 JD] If a filename is sent, that element of the path is not created as a directory.

[2024.09.18 JD] Original code release

 

.NOTES

The -pStrPath sent needs to be fully qualified for this CmdLet to work correctly.

 

Since alot of locations sent will be fully qualified paths with the filename on the end, I now look for a file format as an element

and if the format is *.* a directory is not created.

 

#>

 

    [CmdletBinding()]

    param(

    [Parameter(Position=0, Mandatory=$true)] [string]$pStrPath

    )

 

    $spStrPath = $pStrPath.Split("\")

    if ($pStrPath -like '\\*') { $strPath = "\\"+$spStrPath[2]+"\"+$spStrPath[3]; $ptr=4 } else { $strPath = $spStrPath[0]; $ptr = 1 }

    for ($i=$ptr; $i -lt $spStrPath.Length; $i++) {

        $strPath = $strPath+"\"+$spStrPath[$i]

   

        if ((-not (Test-Path $strPath)) -and (-not ($strPath -like "*.*"))) { mkdir $strPath | Out-Null }

    }

 

    $strPath

 

}