How to Rename a Folder in PowerShell (With Example)


You can use the following basic syntax to rename a folder in PowerShell:

Rename-Item -Path "c:\path\to\old_folder" -NewName "new_folder"

This particular example renames the folder named old_folder located at the path that we specified to new_folder instead.

If you’re already in the current directory where the folder that you want to rename exists, then you can simplify the syntax to:

Rename-Item -Path "old_folder" -NewName "new_folder"

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

Example: How to Rename a Folder in PowerShell

Suppose that we have a directory with the following path:

  • c:\users\bobbi\current_data

We can use the following syntax to list out only the folder names in this directory:

Get-ChildItem c:\users\bobbi\current_data -Directory

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

We can see that three folders currently exist in this directory:

  • data1
  • data2
  • data3

Suppose that we would like to rename the data3 folder to data4 instead.

We can use the following syntax to do so:

Rename-Item -Path "c:\users\bobbi\current_data\data3" -NewName "data4"

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

PowerShell rename folder

We can see that the data3 folder has been renamed to data4 and all other folder names in the directory have remained untouched.

By using the Get-ChildItem cmdlet, we can see the folder names that now exist in the directory:

  • data1
  • data2
  • data4

Note: If the folder path that you specify after the -Path operator does not exist then you will receive an error that tells you the item cannot be renamed because it does not exist.

Related Tutorials

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

PowerShell: How to Copy and Rename a File
PowerShell: How to Rename File Extension of Multiple Files
PowerShell: How to Replace Every Occurrence of String in File

Leave a Reply