Skip to content

Instantly share code, notes, and snippets.

@330k
Last active August 6, 2021 16:54
Show Gist options
  • Save 330k/4d21392ef14debc99a9e2162531c163d to your computer and use it in GitHub Desktop.
Save 330k/4d21392ef14debc99a9e2162531c163d to your computer and use it in GitHub Desktop.
function Get-ChildFilePath {
<#
.SYNOPSIS
Get-ChildFilePath returns a list of file paths of children recursively.
This supports long file name (>256 characters).
.DESCRIPTION
Get-ChildFilePath returns an array of string of full path,
in contrast to Get-ChildItem, which returns an array of object.
Get-ChildFilePath is twice as Get-ChildItem.
.PARAMETER Path
Parent directory path
.INPUTS
Get-ChildFilePath supports pipeline input to $Path.
.OUTPUTS
a list of file paths ([String[]]).
.EXAMPLE
PS C:\Sample> Get-ChildFilePath "C:\"
#>
[CmdletBinding()]
[OutputType([String[]])]
param (
[Parameter(Mandatory,ValueFromPipeline)]
[string]$Path
)
BEGIN {
$notexist = 'C:\DOESNOTEXIST';
while (Test-Path $notexist){
$notexist += Get-Random $(48..57+97..122) | % {[char]$_}
}
}
PROCESS {
if( Test-Path $Path ){
$list = robocopy.exe $Path $notexist /L /E /B /NP /FP /NS /NC /NJH /NJS /NDL |
ForEach-Object { $_.Trim() } | Where-Object { $_.Length -gt 0 }
@($list)
} else {
@()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment