Thursday, November 29, 2018

powershell - Batch renaming of files by calculating a value and using it in the new name

I have a few hundred JPGs that need to be renamed. I need the following simple equation applied to the existing number in each file name:



(x-290)*-1




"Vitrine Hinge.0.jpg" would become "Vitrine Hinge.290.jpg", "Vitrine Hinge.1.jpg" would become "Vitrine Hinge.289.jpg", and so on.



Some of the files in question



I have used the following:



Dir *.jpg | `
foreach {
$data = $_.name.Split(".")
Rename-Item -NewName { '(' + $data1 + '-290)(-1)' }

}



And I receive errors.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...