Ever found yourself staring at a folder full of files and wishing you could batch append them all with a .txt suffix? PowerShell makes this delightfully simple with a one-liner:
Get-ChildItem -File | Rename-Item -NewName {$_.Name + '.txt'}
To expand further to include files in all sub folders, use below instead.
Get-ChildItem -File -Recurse | Rename-Item -NewName { $_.Name + '.txt' }
If you wish to rollback what you just did, use the following:
Get-ChildItem -Path . -Recurse -File -Filter "*.txt" | ForEach-Object {
$newName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
Rename-Item -Path $_.FullName -NewName $newName
}
Feel free to replace the txt with a different one based on your needs!
No comments:
Post a Comment
Do provide your constructive comment. I appreciate that.