Skip to content

Instantly share code, notes, and snippets.

@otobrglez
Created April 14, 2023 09:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otobrglez/88fae800a49b667e804a8253a29bd7e4 to your computer and use it in GitHub Desktop.
Save otobrglez/88fae800a49b667e804a8253a29bd7e4 to your computer and use it in GitHub Desktop.
Recursively renaming files with PowerShell
# Oto Brglez - <otobrglez@gmail.com>
$folderPath = "dodo-was-here" | Resolve-Path
Get-ChildItem -Path $folderPath -Recurse -File |
ForEach-Object {
$newName = Join-Path (Split-Path $_.FullName) `
-ChildPath ($_.FullName -replace $folderPath,'' -replace '/|\\','-' -replace '^(.)','')
Rename-Item -Path $_.FullName -NewName $newName -Force # -WhatIf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment