• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Tips 'n Tricks » Batch Rename File Extensions with Command Prompt / PowerShell

Batch Rename File Extensions with Command Prompt / PowerShell

Posted on December 28, 2012 by Renji | Short URL: http://sumtips.com/?p=7823

In this post I will show you how to rename file extensions in Windows from the command line. We’re going to do this using the built-in Command Prompt and Windows PowerShell. No third-party tools are required.

Rename File Extensions Using Command Prompt

  • Rename all file extensions in a folder

To rename all file extension in a folder we can just use the rename command. For example, say you have a folder with 100s of jpeg files, and you want to rename them to .jpg. You can do that with this command:

rename *.jpeg *.jpg

And you’re done. This command works only in the directory you’re in. So if you wanted to rename extensions of files in sub-folders as well, this wouldn’t do. To do that, have a look at the next command.

  • Rename all file extensions in a folder and its sub-folders

To recursively rename extensions in all sub-folders you can use this command:

forfiles /S /M *.jpeg /C "cmd /c rename @file @fname.jpg"

Rename Using Command Prompt

Rename File Extensions Using Windows PowerShell

  • Rename all file extensions in a folder

To rename extensions of all file in a folder, you can use this PowerShell command:

Get-ChildItem *.jpeg | Rename-Item -newname { $_.name -replace '.jpeg','.jpg' }

Just like with the first Command Prompt command, this works only in the directory you are in.

  • Rename all file extensions in a folder and its sub-folders

To rename extensions in the main folder as well as all its sub-folders, you just have to add the -Recurse parameter to the above command. This will give you something likes this:

dir -Recurse *.jpeg | Rename-Item -newname { $_.name -replace '.jpeg','.jpg' }

Rename using Windows PowerShell
This command will scan and rename all .jpeg files to .jpg in the sub-folders. Did you notice I’ve used Dir here? Well, Dir is just an alias for Get-ChildItem. You can use either.


Tweet

Related posts:

  • Increase Command Prompt and PowerShell Width & Line History
  • Open Explorer Folder from Current Command Prompt Directory Path
  • Save or Print Output from Windows Command Prompt to a Text File
  • Recursively Delete a Specific File Type from all Subfolders
  • Delete Files To Recycle Bin From Command Prompt on Windows
Categories: Tips 'n Tricks | Tags: Command Prompt, PowerShell, Windows
Change Windows Store Region to View Apps from Other Countries
How to Add Dropbox in Office 2013 as a Cloud Storage Service

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Google Docs Gets a New Interface
    • Enable Auto-Resume Playback in Media Player Classic & Winamp
    • Laptop Webcam Can Tell If Your Heart is Healthy
    • Batch Rename File Extensions with Command Prompt / PowerShell
    • uTorrent 2.2 Released with Apps Support
    • GeoTag Your Photos
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy