Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Wednesday, November 9, 2011

Rename all the files in a directory to lowercase with PowerShell

Here is a case where I was thinking to much.  While I was naming about 500 image files for an app that I was working on, I named them in all uppercase lettering.  Well, lowercase was required.  I then started writing a small PowerShell function to go through the folder and rename every image file to lowercase.  Way to much work.  It ended up being a one liner.

Get-ChildItem *.txt | ForEach {$_ | Rename-Item -NewName $_.Name.TpLower()}

Seriously, it is that easy.

2 comments:

van33 said...

The code doesn't work... Could you post a step by step instruction and check the code as well?

Thanks.

I'm running Windows 7 64 bit and copied and pasted the code in PowerShell (x86).

Jason Yoder, MCT said...

Thank you Van33. I did have a typo. I also rewrote the code using object enumeration.

Jason