About My Blog



Whenever I get stuck doing something - the time comes to venture in the world of internet to find solution. In most cases I do find the solution, solve my problem and go on with my life. Then one day I am faced with the same problem. But now - I can't remember how the hell I solved it the first time. So the cycle begins again. Then I thought, what if I can remember all the those things? So here it is, my Auxiliary Memory. I decided to save all the problems and their solution in this blog so that I can get back to them when I need them. And the plus point is - so can everybody else.

Friday, October 31, 2014

Batch File Renaming with Windows PowerShell

I have been in situations where I needed to batch rename a lot of file. There are a lot of tool you can find on internet that can do this. But why go through all those software when you have one option available in windows ready for you to use.

Say Hello to PowerShell. To open it just type "powershell" in command prompt or in start menu.

Here are a few things you can easily do with powershell

Change File Extension

Have some .log whom you want to change to .txt? Just run the following command -

dir *.jpeg | rename-item -newname {  $_.name  -replace ".log",".txt"  }

dir command gets the list of files in the current directory. The | (pipe) character passes this list to rename-item command which takes each of the file and replaces it's extension

Appending File Extension

You can append file extension to multiple files which don't have file extension in their name

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

Rename File With Increasing Number

This one's a bit complicated than the other two. It uses a variable to rename the files.
dir *.jpg | ForEach-Object  -begin { $count=1 }  -process { rename-item $_ -NewName "image$count.jpg"; $count++ }

No comments:

Post a Comment