Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Last active October 15, 2024 23:19
Show Gist options
  • Save dstreefkerk/7f8910ce6ddfa8fea6206f043f353faa to your computer and use it in GitHub Desktop.
Save dstreefkerk/7f8910ce6ddfa8fea6206f043f353faa to your computer and use it in GitHub Desktop.
PowerShell profile function and alias to copy the current folder's filenames to clipboard
<#
.SYNOPSIS
Retrieves file names from the current folder and copies them to the clipboard.
Drop this function and the alias definition into your PowerShell profile file to make it available in every PowerShell session.
.EXAMPLE
Get-FileNamesFromCurrentFolder -Recurse
Recursively gets all file names from the current folder and subfolders, copying them to the clipboard.
.NOTES
Only file names are returned, not folder names.
#>
function Get-FileNamesFromCurrentFolder {
param (
[switch]$Recurse
)
Get-ChildItem -File -Recurse:($Recurse.IsPresent) | Select-Object -ExpandProperty Name | Set-Clipboard
}
New-Alias -Name filenames -Value Get-FileNamesFromCurrentFolder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment