Skip to content

Instantly share code, notes, and snippets.

@scottmwyant
Created October 28, 2019 02:28
Show Gist options
  • Save scottmwyant/3e39a9b36ba400b99e1da325d1dab596 to your computer and use it in GitHub Desktop.
Save scottmwyant/3e39a9b36ba400b99e1da325d1dab596 to your computer and use it in GitHub Desktop.
powershell -NoExit -Command{
# Get started
Clear-Host
Write-Host
Write-Host 'Welcome to the Find-File utility!'
Write-Host
# Get the path from the user
$myPath = Read-Host -Prompt ' Path'
# See if the user wants to include sub-folders
$transverse = Read-Host -Prompt ' Sub-folders (y/n)'
if($transverse -eq 'y'){$transverse = $true}
else{$transverse = $false}
# Get the list of file types from the user
[string[]] $fileFilter = (Read-Host -Prompt ' File filter').Split(', ').Split(',').Split(' ')
if($fileFilter[0] -eq ''){$fileFilter[0] = '*'}
Write-Host
Write-Host ' Note: this script is an alternative to:'
Write-Host ' dir /S/B {filter} in cmd.exe'
# Execute the script
Set-Location $myPath
Get-ChildItem -Path:$myPath -Recurse:$transverse -Include $fileFilter | Select-Object fullname
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment