PowerShell: How to Convert Filenames to Lowercase


Often you may want to use PowerShell to convert the filename of each file in a folder to lowercase.

You can use the following syntax to do so:

gci | foreach { if ($_.Name -cne $_.Name.ToLower())
  { ren $_.FullName $_.Name.ToLower() } }

This particular example will convert each filename in the current directory to all lowercase letters.

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.
  • -cne: Performs a case-sensitive comparison to check if the current filename in the foreach loop is not all lowercase. It it is not, then the filename is converted to lowercase using the ToLower() method.
  • ren: An alias for Rename-Item.

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

Example: How to Convert Filenames to Lowercase 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. The first letter of each file is currently capitalized.

We can use the following syntax to convert each of the filenames to all lowercase letters:

gci | foreach { if ($_.Name -cne $_.Name.ToLower())
  { ren $_.FullName $_.Name.ToLower() } }

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

PowerShell convert each filename to lowercase

Notice that when we use the gci command again to view all of the files in the current directory that each filename now has all lowercase letters.

Note: You can find the complete documentation for the ToLower() 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