Last active
June 5, 2024 06:58
-
-
Save sgrodnik/b4b4f1edbd29c3d2fdd6a132e86f791f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use:
.\RenameFiles.ps1 "c:\names.txt"
Example of
c:\names.txt
(tab-separated data):