Thursday, November 18, 2021

Rename files using power shell

I definitely miss Linux a lot. However, my main working environments are in Windows. It has been 5 years!

Just had a call with one of the customers. I need to rename 100+ files. Sigh. During the call, I had time pressure, and I couldn't tolerate with continuous of try and error. So, I used the slowest and safest but human-error-proned way of doing it, rename it manually, one by one.

We got silence moment in the call, then we suggested to communicate via email to sync up. Phew, pressure went away. So I did a quick Google search. I have tried to search for this solution for several times, but I never get it right, get it work. Probably I am still unconsciously resisting to PowerShell. Anyway, recently I seems to have more luck with PowerShell!

Then, in a few minutes, I finally found the "ultimate" solution!

Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace 'a','b' }


And then, suddenly I found out, I forgot how to do this in Linux... Sigh.

* update

This is the equivalent Linux command:

rename 's/a/b/' *.txt


No comments:

Post a Comment