Skip to content

Instantly share code, notes, and snippets.

@berdosi
Last active January 28, 2020 10:10
Show Gist options
  • Save berdosi/95466b54c9b299055395544b75e82146 to your computer and use it in GitHub Desktop.
Save berdosi/95466b54c9b299055395544b75e82146 to your computer and use it in GitHub Desktop.
Powershell snippet to do something with items with matching names in a directory
Get-ChildItem |
Where-Object -Property "Name" -Like "*remove this part from the filename*" | # filtering
ForEach-Object {
# action to do. Case in point: rename the file. Note the parentheeses around the two parameters.
Move-Item ($_.Name) ([System.Text.RegularExpressions.Regex]::Replace($_.Name, "remove this part from the filename", ""))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment