deva deva - 1 year ago 103
PowerShell Question

Change file name into Title Case in buk

I have bulk image files that I want to change their filenames into Title Case via PowerShell.

For example:

file name like this.jpg


File Name Like This.jpg

I have 700+ files in sub folders.

I have tried this code:

Get-ChildItem "C:\temp\new" -recurse |Where {-Not $_.PSIsContainer} |Rename-Item -NewName {$_.FullName.TOUPPER()}

But this code capitalizes all letters.

Answer Source

So PowerShell actually has a super simple way to do that using Get-Culture's textinfo. That property contains a method called ToTitleCase() which will do exactly (almost) what you want. The only difference being that it will also capitalize the 'J' in 'Jpg'. Just the extension though, so no big deal right?

$Culture = Get-Culture
Get-ChildItem "C:\temp\new" -recurse |Where {-Not $_.PSIsContainer} |Rename-Item -NewName {$Culture.textinfo.totitlecase($_.FullName)}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download