PowerShell: How to Capitalize First Letter of Each Filename


Often you may want to use PowerShell to capitalize the first letter of each file in a folder.

You can use the following syntax to do so:

gci | foreach {
$NewName = (Get-Culture).TextInfo.ToTitleCase($_); ren $_.FullName $NewName}

This particular example will capitalize the first letter of each filename in the current directory.

Here is what the various commands do:

  • gci: An alias for Get-ChildItem, this retrieves all files in the current directory.
  • foreach: Specifies an action to perform on each file.
  • (Get-Culture).TextInfo.ToTitleCase($_): Defines new name of file to be current name. displayed in title case, which capitalizes the first letter of each word in the filename.
  • ren: An alias for Rename-Item, this renames the filename using the new name.

The following example shows how to use this syntax in practice.

Example: Capitalize First Letter of Each Filename in PowerShell

First, we can use the gci command (an alias for the Get-ChildItem cmdlet) to first view all filenames in our current directory:

We can see that there are three files in our current directory that all have lowercase filenames.

We can use the following syntax to capitalize the first letter of each filename:

gci | foreach {
$NewName = (Get-Culture).TextInfo.ToTitleCase($_); ren $_.FullName $NewName}

The following screenshot shows how to use this syntax in practice:

PowerShell capitalize first letter of filename

Notice that when we use the gci command again to view all of the files in the current directory that the first letter of each filename has been capitalized.

Note: You can find the complete documentation for the ToTitleCase() method here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Get File Name from Path
PowerShell: How to Add Date to File Name
PowerShell: How to Delete All Files with Specific Extension

Leave a Reply