I was manually renaming about 450 files for a project I'm working on and realized 400 in that it would be easier if "y" came first in the order, but I was too far in by that point to change it. Is there I way I could automatically do that?
Example:
-cloth_ball.properties
-cloth_puppet.properties
-plastic_ball.properties
-plastic_puppet.properties
-wooden_ball.properties
-wooden_puppet.properties
Needs to be:
-ball_cloth.properties
-ball_plastic.properties
-ball_wooden.properties
-puppet_cloth.properties
-puppet_plastic.properties
-puppet_wooden.properties
I looked for other batch renaming options for help, but I couldn't find any that would help with this specific issue.
Assuming you have an array of strings:
You can first use the regex pattern
(?<=-)([^_]+)_([^.]+)with-replaceoperator, and thenSort-Objectfor sorting them:See https://regex101.com/r/e7kggt/2 for regex details.