Bulk Rename with Windows Powershell

I also know that there is third party applications which are really good at this job but if you wanna feel a little bit geeky like me, try this!!

First let us assume that we have bunch of files together in a folder.  Their name are pretty confusing and random because let’s say that we have downloaded them all. For our super important project we need their names to become meaningful and useful.

Bulk Rename
Before – After Rename

1. Open Start menu (or start page) and type “powershell” to find Windows PowerShell and open it.

You can also try to look for it in your start menu or C:\WINDOWS\system32\WindowsPowerShell directory. 

2. Set working directory to the directory with your random files.

You can use “cd [directory name]” for walking into the directory “cd ..” for going to outer directory.

3. Decide what you want to create algorithm. In this post I will arrange the names “[random].html” as “page[number].php”

Dir *.html | ForEach-Object -begin { $count=1 } -process { rename-item $_ -NewName "page$count.php"; $count++ }
Windows PowerShell Rename
Windows PowerShell Rename

Dir *.html | part is to get all the html files in that dir and create something sort of an array before processing.

ForEach-Object is to the process file by file.

-begin { $count=1 } mean we start counting from 1.

-process { rename-item $_ -NewName "page$count.php"; part does the trick.