Skip to main content

Batch File Rename with Windows PowerShell

Posted June 2011 by Steve Sinchak

Microsoft included a batch rename feature in the latest version of Windows allowing you to select multiple files, right click on one and select rename. All of the selected files will be renamed with the name you provided and a number. This functionality works well for basic files but does not provide any flexibility in exactly how the files are numbered and also does not allow the file extension to be changed.

Windows PowerShell, which is included in Windows starting with Vista and 2008 Server and available for XP, provides the raw tools to allow you to perform batch file renames. The trick is to pipe the output of one command into another command allowing you to connect the functionality to produce a useful outcome.

The two PowerShell commands needed for batch file renaming are dir (which is an alias for get-childitem) and rename-item.

To get started I suggest copying all the files you need to rename to a separate directory.  Then, open up Windows PowerShell and navigate to the directory with the CD command.

Depending on how you want to rename the files there are a few different techniques:

Changing the File Extension of all .jpeg files to .jpg

Dir *.jpeg | rename-item -newname {  $_.name  -replace ".jpeg",".jpg"  }

In the above example the $_ represents each item passed to the rename-item command via the pipe | from the dir command.

Appending a File Extension

Dir | rename-item -newname  { $_.Name +".jpg" }

File Rename with Customizable Increasing Number

Dir *.jpg | ForEach-Object  -begin { $count=1 }  -process { rename-item $_ -NewName "image$count.jpg"; $count++ }

In the example we needed to use an additional command known as foreach-object that allows you to set a variable (our counter) before looping through each file in the directory and then do an action for each item. The result of the above example are files named image1.jpg, image2.jpg and so on.

Related Posts


The Java Runtime Environment has become one of the most exploited components of any operating system. Even the US Department of Homeland Security warns users to disable java unless they have a really good reason to use it.  For most of us the days of Web sites requiring you to run Java applets has long passed.  However, there still are a good number of desktop applications written in Java so simply...

Read More

Adobe ReaderThe Adobe download manager is part of the normal install of Adobe Reader and Flash that allows Adobe to bundle additional software with their products. After the download manager is installed, Reader/Flash along with other software (Adobe Air) can be downloaded and installed. When dial-up Internet connections where common download managers provided a valuable...

Read More

In the latest version of iOS Apple included a new feature called AirPrint. Designed to bring native printing support to the iOS platform it can be found on version 4.2 or later on devices such as the iPhone, iPod, and iPad. At launch only a handful of HP wireless printers could be used but with the help of this article it is possible to AirPrint to any printer connected to a Windows computer, including...

Read More

The Windows Sysinternals group at Microsoft has released Disk2vhd that is a free physical to virtual converter. Disk2vhd allows you to create VHD (virtual hard dive) files from physical drives on your computer while your system is online. The VHD files generated can be used in Microsoft Virtual PC or on Hyper-V server and you will have an instant clone of your machine running virtually.  This is perfect...

Read More