<# FPS:Containers:Common:Public:Get-Folder:ACTIVE
#>
function Get-Folder {
<#
.DESCRIPTION
Module: Common
Public CmdLet: Get-Folder.ps1
Dependencies: None
Lists all files under the filesystem directory regardless
of character limitation on path depth. This file was originally
pulled from the internet.
Unfortunately, the author and other credits were lost in the
transition.
.USAGE
Called throughout FPS to determine the contents of a
directory.
Parameters:
Path = The type name to list out
available constructors and parameters
Filter = Optional parameter to specify a specific file or
file type. Wildcards (*) allowed. Default is '*.*'
ExcludeFile = Exclude Files matching given
names/paths/wildcards
MaxAge = Exclude files older than n days. Use
to form a delta to extract customizations
MinAge = Exclude files newer than n days. Use to for a delta to extract customizations.
.EXAMPLE
if (Push-NeededFor Get-Folder) { . (Get-ActiveFileNm -PS1
Get-Folder) }
Get-Folder -Path $global:pro_CIBase.RuntimeMetadata
FullName
:
D:\FPS\MetaData\Pro-Config.ps1
ParentFolder : D:\FPS\MetaData\
FullPathLength : 30
Extension : ps1
Name : Pro-Config.ps1
Length : 2316
LastWriteTime : 9/18/2024 2:09:40 PM
FullName
:
D:\FPS\MetaData\Pro-Locations.ps1
ParentFolder : D:\FPS\MetaData\
FullPathLength : 33
Extension : ps1
Name : Pro-Locations.ps1
Length : 3664
LastWriteTime : 9/18/2024 7:30:43 PM
FullName
:
D:\FPS\MetaData\profile.ps1
ParentFolder : D:\FPS\MetaData\
FullPathLength : 27
Extension : ps1
Name : profile.ps1
Length : 8046
LastWriteTime : 9/18/2024 7:30:46 PM
Description
-----------
Returns all files under a folder.
EXAMPLE:
if (Push-NeededFor Get-Folder) { . (Get-ActiveFileNm -PS1
Get-Folder) }
$fileSet = Get-Folder -Path $global:pro_CIBase.RuntimeMetadata
$fileList = $fileSet | Select FullName, LastWriteTime
$fileList
FullName LastWriteTime
--------
-------------
D:\FPS\MetaData\Pro-Config.ps1 9/18/2024 2:09:40 PM
D:\FPS\MetaData\Pro-Locations.ps1 9/18/2024 7:30:43 PM
D:\FPS\MetaData\profile.ps1 9/18/2024 7:30:46 PM
Description
-----------
Provides a list that can be used to move files to the
build directory
if (Push-NeededFor Get-Folder) { . (Get-ActiveFileNm -PS1
Get-Folder) }
$fileSet = Get-Folder -Path $global:pro_CIBase.RuntimeContainer
$fileList = $fileSet | Group-Object ParentFolder
| Select Count, Name
$fileList
Count Name
----- ----
4
D:\FPS\Containers\
2
D:\FPS\Containers\Aloha-P1\Common\
4
D:\FPS\Containers\Aloha-P1\Common\Common\
4
D:\FPS\Containers\Aloha-P1\Common\Common\Private\
19
D:\FPS\Containers\Aloha-P1\Common\Common\Public\
4
D:\FPS\Containers\Aloha-P1\DataResources\
This example shows Get-Folder stored in $files then pipeing to Group-Object which is used with $files to show
the
count of files in each folder under the operations
directory.
$MinDt = '2024-09-18'
$Now = Get-Date
$HowMany = New-TimeSpan -Start $MinDt -End $Now
$Dir = $global:pro_CIBase.RuntimeContainer
$files = Get-Folder -Path $Dir -MinAge
$HowMany.Days
$fileSet = $files | Select FullName, LastWriteTime
$MaxDt = '2024-06-18'
$HowMany = New-TimeSpan -Start $MaxDt -End $Now
$files = Get-Folder -Path $Dir -MaxAge
$HowMany.Days
$fileSet += $files | Select FullName, LastWriteTime
Out-File -FilePath ($global:pro_Locations.CommonScratch+'\demoFileList.txt') -InputObject $fileSet -Encoding
ASCII -Width 400
Description
-----------
COTS's builds are typically
built on a specific date. To pull out all of the customized files from a particular build, find
that date
and pull all files before and all files after to find all
the "potential" customizations made in the last build
filesystems. NOTE: Make
sure to pull all the hotfixes out of the selection list.
.CC
[2024.09.25 JD] Original code release
.Notes
This file was originally pulled from the internet. Unfortunately, the author and other credits
were lost in the transition. Please
inform boxercentral@verizon.net of any credits that
should be applied to the CmdLet.
#>
[cmdletbinding(DefaultParameterSetName='Filter')]
Param (
[parameter(Position=0,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
[Alias('FullName')]
[string[]]$Path = $PWD,
[parameter(ParameterSetName='Filter')]
[string[]]$Filter = '*.*',
[parameter(ParameterSetName='Exclude')]
[string[]]$ExcludeFile,
[parameter()]
[int]$MaxAge,
[parameter()]
[int]$MinAge
)
Begin {
$params = New-Object System.Collections.Arraylist
$params.AddRange(@("/L","/S","/NJH","/BYTES","/FP","/NC","/NDL","/TS","/XJ","/R:0","/W:0"))
If ($PSBoundParameters['MaxAge']) {
$params.Add("/MaxAge:$MaxAge") | Out-Null
}
If ($PSBoundParameters['MinAge']) {
$params.Add("/MinAge:$MinAge") | Out-Null
}
}
Process {
ForEach ($item in $Path) {
Try {
$item = (Resolve-Path -LiteralPath $item -ErrorAction Stop).ProviderPath
If (-Not (Test-Path -LiteralPath $item -Type Container -ErrorAction Stop)) {
Write-Warning ("{0} is not a directory and will be skipped" -f $item)
Return
}
If ($PSBoundParameters['ExcludeFile']) {
$Script = "robocopy `"$item`" NULL $Filter $params /XF $($ExcludeFile -join ',')"
} Else {
$Script = "robocopy `"$item`" NULL $Filter $params"
}
Write-Verbose ("Scanning {0}" -f $item)
Invoke-Expression $Script | ForEach {
Try {
If ($_.Trim() -match "^(?<Size>\d+)\s(?<Date>\S+\s\S+)\s+(?<FullName>.*)") {
$object = New-Object PSObject -Property @{
ParentFolder = $matches.fullname -replace '(.*\\).*','$1'
FullName = $matches.FullName
Name = $matches.fullname -replace '.*\\(.*)','$1'
Length = [int64]$matches.Size
LastWriteTime = [datetime]$matches.Date
Extension = $matches.fullname -replace '.*\.(.*)','$1'
FullPathLength = [int] $matches.FullName.Length
}
$object.pstypenames.insert(0,'System.IO.RobocopyDirectoryInfo')
Write-Output $object
} Else {
Write-Verbose ("Not matched: {0}" -f $_)
}
} Catch {
Write-Warning ("{0}" -f $_.Exception.Message)
Return
}
}
} Catch {
Write-Warning ("{0}" -f $_.Exception.Message)
Return
}
}
}
}