Skip to content

Instantly share code, notes, and snippets.

@sgrodnik
Last active June 5, 2024 06:58
Show Gist options
  • Save sgrodnik/b4b4f1edbd29c3d2fdd6a132e86f791f to your computer and use it in GitHub Desktop.
Save sgrodnik/b4b4f1edbd29c3d2fdd6a132e86f791f to your computer and use it in GitHub Desktop.
param (
[Parameter(Position = 0, Mandatory = $true)]
[string]$filePath
)
$lines = Get-Content $filePath
foreach ($line in $lines) {
$parts = $line -split '\t'
$oldName = $parts[0]
$newName = $parts[1]
try {
Rename-Item -Path $oldName -NewName $newName -ErrorAction Stop
Write-Host "OK $oldName" -ForegroundColor Green
} catch {
Write-Host "Error $oldName : $_" -ForegroundColor Red
}
}
@sgrodnik
Copy link
Author

sgrodnik commented Jun 5, 2024

How to use:

  1. Run PowerShell terminal
  2. Run command: .\RenameFiles.ps1 "c:\names.txt"

Example of c:\names.txt (tab-separated data):

c:\path\oldName1	newName1  
c:\path\oldName2	newName2  
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment