Skip to content

Instantly share code, notes, and snippets.

@stelf
Created March 24, 2022 15:09
Show Gist options
  • Save stelf/3dccf2c96d666b4a5959ebc7619da272 to your computer and use it in GitHub Desktop.
Save stelf/3dccf2c96d666b4a5959ebc7619da272 to your computer and use it in GitHub Desktop.
Use System.IO.Directory to find files in .NET (faster than gci)
function Find-Files {
[CmdletBinding()]
param(
[Parameter()] [string] $Glob,
[Parameter()] [string] $Path = (Get-Location))
if (-not ( $Path -match '^\w:' ) ) {
$Path = (Get-Location).Path + '\' + $Path
}
Write-Host searching for $Glob in $Path. skip directories.
[System.IO.Directory]::EnumerateFiles(
$Path, $Glob, 'AllDirectories')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment