Go Back   TechArena Community > Software > Tips & Tweaks
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to rename Batch File with Windows PowerShell

Tips & Tweaks


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-08-2012
Member
 
Join Date: May 2009
Posts: 218
How to rename Batch File with Windows PowerShell
  

> Latest version of windows come up with a batch rename feature, using this feature one can select multiple files, right click on one and rename them all after selecting rename. This batch rename feature has been found to be working out for basic files but it doesn’t provide flexibility and doesn’t change file extensions. Windows PowerShell has been included in Windows XP, windows 2008 Server and windows vista. PowerShell is a raw tool for carrying out batch file renames. Dir and rename-item are two PowerShell commands required for batch file renames, dir is an alias for get-childitem.


For carrying out this task you can copy all files you might be willing to rename in different directory and open Windows PowerShell. After that you can navigate to the directory using CD command. There are different techniques for renaming the files and you can use the one accordingly.

For changing File Extension of all .jpeg files to .jpg you can use below command:

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

In above command $_ represents items which are passed to rename-item command via pipe | from dir command.

For appending a File Extension:

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

For renaming with Customizable Increasing Number:

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

In above command one can use additional command which is known as foreach-object for setting a variable before looping files in directory and carrying out the action for each item. Result of this command will be image1.jpg, image2.jpg and so on.

Reply With Quote
Reply

  TechArena Community > Software > Tips & Tweaks
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to rename Batch File with Windows PowerShell"
Thread Thread Starter Forum Replies Last Post
How to Batch rename in Photoshop Elements 8 Bhaisora Windows Software 7 20-12-2011 06:03 AM
Running Powershell script with batch file with parameters? Jaslein Software Development 3 12-01-2011 03:36 AM
Want to rename batch files with a random name Crockodoo Windows Software 5 20-10-2010 12:08 PM
Batch file to rename a file WeDaFaKaWe Tips & Tweaks 3 02-09-2010 11:40 PM
How to rename batch pics Mohegan Windows Software 6 01-06-2010 06:38 PM


All times are GMT +5.5. The time now is 02:44 AM.