Skip to content

Month: February 2016

How to remove text from file name for multiple files on Windows

On Windows, you can take advantage of PowerShell:

dir | rename-item newname { $_.name ireplace '(.+?) 203\.bmp$','$1.bmp' }

In this code snippet we use a command that removes ‘203’ from the file name.

Description

dir          => list the content of the current directory
 |           => send each found element to the next command
rename-item  => rename an element in a Windows PowerShell provider namespaceject
newname     => specify the name of the renamed file
{
    $_               => points to an object representing the actual file
   .name             => the name property of the automatic variable
   -ireplace         => perform a insensitive replace
   '(.+?) 203\.bmp$' => here comes the regex for matching the desired files
   '$1.bmp'          => the replacement string
}

You must run this command inside a power shell. Here is how to start it:

how to launch powershell on Windows 7?

Then cd into you dir from the Powershell window:

Change to the directory containing the files to be renamed from powershell window

More on http://stackoverflow.com/questions/21837836/how-to-rename-multiple-files-at-once-by-removing-a-varying-part-in-the-file-name

Also – http://superuser.com/questions/236820/how-do-i-remove-the-same-part-of-a-file-name-for-many-files-in-windows-7/871799