Each time I do PowerShell now, it saddens me. I haven’t used it much for the past year I am slowly forgetting even the basic stuff. I really must do some PowerShell coding project soon just to amp up my skills.
Anyhoo, I needed to rename a bunch of files quickly today. Used the following to rename them:
1 |
Get-ChildItem | %{ $name = $_.name; if ($name -match "^(.*) \(digital.*\)\.cbz$") { $newname = $matches[1]; Rename-Item -Path $name -NewName "$newname.cbz" } } |
The files were of the format “The Title (digital) Extra Stuff.cbz
“. I wanted to rename it such that the new file name is only the underlined parts. Above code does that to a directory full of such files.