<# FPS:Containers:Make:Public:Get-ActiveFileNm:ACTIVE
#>
function Get-ActiveFileNm {
<#
.DESCRIPTION
Module: Make
Public CmdLet:
Get-ActiveFileNm.ps1
Has Dependencies: No
This CmdLet gets the most
recent active filename for the CmdLet selected. This returns the active filename
so the cmdlet can be loaded. The CmdLet is
loaded in the Pro-Config file so it is available at
all times.
Get-ActiveFileNm relies on the
accuracy, uniqueness, and status indicated within the header of all code
files.
.EXAMPLE
if (Push-NeededFor Get-Answer) { . (Get-ActiveFileNm -PS1
Get-Answer) }
.CC
[2024.09.28 JD] Original Source for $LookIn
was updated to $global:pro_CIAttributes.SourceDrive
[2024.09.18 JD] Original code release
.NOTES
There should not be any objects within the container path
as the compiled object could possibly incorrectly
match.
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)] [string]$PS1,
[Parameter(Mandatory=$false)] [string]$Target # Where the file is searched. Source/Runtime, default is Runtime
)
# Determine the location for the search
if ($Target -eq 'Source') {
$LookIn = $global:pro_CIAttributes.SourceDrive+'\FPS\Containers'
} else { # Default is Runtime
$LookIn = $global:pro_CIBase.RuntimeRoot+'\Containers'
}
# The filename sent can be the tail of the filename, or
entire filename - it just has to correctly identify
the file.
$LookFor = $PS1+':ACTIVE' #
By adding :ACTIVE we basically weed out all other usages of the handle
$FoundAt = Get-ChildItem $LookIn -Recurse | Select-String -Pattern $LookFor
if ($FoundAt.length -eq 1) {
[string]$CurrentPS1=$FoundAt
} else {
[string]$CurrentPS1=$FoundAt[$FoundAt.length-1]
}
$SpCurrentPS1 = $CurrentPS1.split(':')
$PS1SrcFile = $SpCurrentPS1[0]+':'+$SpCurrentPS1[1]
$PS1SrcFile # Output the discovered filename
}