How do I remove the same part of a file name for many files in Windows 7?

88

67

Basically, I have an album of music and I want to remove the authors name from all of the mp3 files instead of having to manually do it myself. Is there a function in Windows 7 Ultimate that can do this for me?

alt text

qroberts

Posted 2011-01-23T17:42:00.670

Reputation: 4 609

Answers

140

You could also try using PowerShell, a powerful Windows command line tool. You'd run this command:

Full Command:

get-childitem *.mp3 | foreach { rename-item $_ $_.Name.Replace("Radiohead -", "") }

Analyzing it:

get-childitem *.mp3
This lists all files whose names end with .mp3.  They are then piped to the next command with the | operator.

foreach { rename-item $_ $_.Name.Replace("Radiohead -", "") }
This replaces all instances of Radiohead - with nothing, denoted by "", effectively wiping the word from all the files in the directory.

You could also modify get-childitem *.mp3 to get-childitem – that would rename all the files in the directory, not just files whose names end with .mp3.

Zain Patel

Posted 2011-01-23T17:42:00.670

Reputation: 1 920

5What does $_ $_. represent? Thanks! – paulkon – 2016-07-18T15:52:19.470

5@paulkon it represents whatever item was piped through from the previous command. In this case, it represents each item as they're yielded by foreach loop. The $_. follows the dot notation to access properties/methods/elements. So $_.Name accesses the Name property of each file that is piped through by get-childitem. – airstrike – 2016-10-26T23:51:44.497

1for recursive rename, just add -recurse parameter to get-childitem – Kreker – 2017-10-10T09:08:21.523

1Thanks for this solution... worked a charm. I am sat here wondering how you get it to also modify files in sub-folders too? like how -R works on linux. I am a linux head. – josh.thomson – 2017-11-07T12:48:36.077

Really great solution with PowerShell, this also works for Postfix Replace! I just tested it on 4.000 files like so: Get-ChildItem *.svg | ForEach-Object {Rename-Item $_ $_.Name.Replace("_16x","")} – Devid – 2018-01-24T10:53:15.557

Is there a way to replace two or more things within a name simultaneously? For instance, I have several .rar files (Issue 1.rar, Issue 2.rar, etc.) where I want to change both the common first word "Issue" of each file, and change each extension to .cbr. – Denise Gi – 2018-04-22T12:01:49.957

@DeniseGi there is, but it's probably easier to just run the command twice. – Zain Patel – 2018-04-22T19:33:17.700

Ha, okay, that's what I've been doing. Thanks. – Denise Gi – 2018-04-22T20:13:55.620

3Don't forget to add -LiteralPath if you have things like square brackets in the name. Other than that tyvm for this answer! Upvoted – josh.thomson – 2018-06-22T19:41:41.110

1Concise version: gci *.mp3 |%{ ren $_ $_.name.replace("Radiohead -", [string]::empty) } – Ian Kemp – 2018-11-05T07:06:34.257

@IanKemp there is similar approach, like ls *.csv | Rename-Item -NewName {$_.name -replace "Default","VOD"} However please note that the search pattern parameter "Default" is parsed like a regex by default. .Replace can be used for dummy string, like ls *.csv | Rename-Item -NewName {$_.name.Replace("Default","VOD")}

– oleksa – 2019-03-15T11:01:05.493

It worked well for me but since I ran it on 1000's of files it took a long time. Any way to parallel it? – Itay.B – 2019-06-03T08:59:34.463

This keeps the original files. – M-- – 2019-06-14T18:43:46.387

How can I use this code if I have a name with brackets, say [Radiohead -]? I tried @josh.thomson comment with -LiteralPath, but with errors. Where in the code should I place -LiteralPath? – JDoeDoe – 2019-08-31T09:17:44.283

-LiteralPath is used after rename-item – Michael Aguilar – 2019-09-14T21:39:23.007

how to handle Chinese characters in file name? – Franva – 2020-01-04T06:57:11.410

58

Forget about complicated scripts for this.

rename is a very old and never properly completed command. If you do not use it properly, the result might surprise you.

For example to remove a prefix abcd from abcd1.txt, abcd2.txt, abcd3.txt etc. in order to get 1.txt, 2.txt, 3.txt simply use

rename "abcd*.txt" "////*.txt"

You need the same number of / as the number of initial characters you would like to remove.

Do place double quotes for both arguments.

user414051

Posted 2011-01-23T17:42:00.670

Reputation:

quick and simple, I like it. Can you explain how it work? Is the slash a null or a folder with no name? – Matt – 2015-12-09T15:28:15.287

1No particular rule. It is as it is. / can be a part of unc path so it is not the same as : < > |. It is probably treated as some sort of invisible path. – None – 2015-12-10T00:55:14.473

Very interesting and useful hack. Too bad it only works for prefixes! – matt wilkie – 2017-05-15T22:42:46.243

1

Fantastic discovery. Very odd that both source and target must be quoted, else get The syntax of the command is incorrect error. I'm curious if this technique has ever been posted anywhere prior to this answer?. I need to update my How does the Windows RENAME command interpret wildcards? Q&A, though technically, the / are not functioning as wildcards.

– dbenham – 2017-06-03T18:48:36.510

Doesn't remove '.' in the file names. eg., dbo.table1.sql, dbo.table2.sql, it renames them to .table1.sql, .table2.sql – GaneshT – 2017-07-25T15:29:43.250

13

This might work.

Create a batch file as follows:

for %%i in ("*.mp3") do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off 1st four chars, then appends prefix
ren "%fname%" "my%fname:~4%"
goto :eof

Source: http://www.codejacked.com/renaming-multiple-files-at-once-windows (in the comments, from "BlueNovember")

user3463

Posted 2011-01-23T17:42:00.670

Reputation:

Disclosure: my answer was edited, so it is no longer an exact copy of the comment I referenced. – None – 2013-11-19T21:24:29.060

12

Try this software

http://www.bulkrenameutility.co.uk/Main_Intro.php

Bulk Rename Utility is a free file renaming software for Windows. Bulk Rename Utility allows you to easily rename files and entire folders based upon extremely flexible criteria. Add date/time stamps, replace numbers, insert text, convert case, add auto-numbers, process folders and sub-folders....plus a whole lot more! Rename multiple files quickly, according to many flexible criteria. Rename files in many ways: add, replace, insert text into file names. Convert case, add numbers. Remove or change file extensions. Check the detailed preview before renaming. Rename photos using EXIF meta data (i.e. "Date Picture Taken", "Resolution" and other information embedded in all JPG photo files) Rename your holiday pictures from a meaningless dsc1790.jpg to NewYork1.jpg in a flash. Rename MP3 files using ID3 tags (a.k.a. MP3 ID3 tag renaming). Change files' creation and modification time stamps. It's free. Easy to Install. Download and start renaming your files now!

Moab

Posted 2011-01-23T17:42:00.670

Reputation: 54 203

3thanks. I saw this in google search but have to be careful with installing random software. given your rep and recommendation I installed it and it is incredible. No fiddling with powershell etc. I am a programmer and love the Trim, regex features. It works better than advertised. I highly recommend this too. ups! – Abhishek Dujari – 2013-03-11T10:03:29.887

12

ReNamer can do that. In ReNamer, just add a 'remove' rule like this (a 'delete' rule will also work):

ReNamer 'remove' rule

And then drag and drop the files, or the folder containing the files you want renamed to its window (or use the 'Add Files/Folders' buttons), then check the preview, and once verified, click on 'Rename':

ReNamer window

galacticninja

Posted 2011-01-23T17:42:00.670

Reputation: 5 348

10

Since you are dealing with music files, forget about the batch file and utilities to rename your files. Use a dedicated program such as Mp3tag which is an absolute must if you're really into organizing your music.

Main features

Batch Tag Editing Write ID3v1.1, ID3v2.3, ID3v2.4, MP4, WMA, APEv2 Tags and Vorbis Comments to multiple files at once.

Support for Cover Art Download and add album covers to your files and make your library even more shiny.

Import from Amazon, discogs, freedb, MusicBrainz Save typing and import tags from online databases like Amazon, discogs, freedb, MusicBrainz, and more.

Replace characters or words Replace strings in tags and filenames (with support for Regular Expressions).

Create Playlists automatically Create and manage playlists automatically while editing.

Rename files from tags Rename files based on the tag information and import tags from filenames.

Export to HTML, RTF, CSV Generate nice reports and lists of your collection based on user-defined templates.

Full Unicode Support User-interface and tagging are fully Unicode compliant.

Besides these main features Mp3tag offers a variety of other functions and features ranging ranging from batch export of embedded album covers, over support for iTunes-specific tags like media type or TV Show settings, to combining multiple actions into groups that can be applied with a single mouse click.

Metro Smurf

Posted 2011-01-23T17:42:00.670

Reputation: 918

4

I just want to add my favorite: Rename Master

This utility will add, remove, or replace parts of the filename with ease and also supports renaming via file properties, MP3 tags, JPEG JFIF and EXIF tags, Video tags, and text files. Batch renaming that's simple to use, yet still very powerful.

enter image description here

Features

  • Portable mode
  • Intelligent number sorting
  • Full Unicode filename support
  • File and folder renaming
  • Custom filelist columns
  • Auto-Preview
  • Subfolder Scanning to rename files in multiple folder
  • Renaming Variables for JPEG/MP3/Video tags, file properties, counters, and more
  • Scripts to save commonly used renaming options
  • [*] and [?] command prompt style wildcards, or full Regular Expression support
  • Optional Explorer integration for right-clicking on files/folders or using "Send To"
  • Case Changing and Textfile importing
  • Command line options for batch renaming

nixda

Posted 2011-01-23T17:42:00.670

Reputation: 23 233

3

I had a related requirement.

CAUTION:
Take a backup of the folder on which you are trying the below commands.


Example 1:

CAUTION: This command overwrites a part of the existing file name

If you have only two files in a directory:

This is file 1.txt  
This is file 2.txt  

and if you run:

rename "\*.\*" "abc-\*.\*"  

Then, the files get changed to:

abc- is file 1.txt  
abc- is file 2.txt  

Example 2:

CAUTION: This command deletes a part of the existing file name

If you have only two files in a directory:

This is file 1.txt  
This is file 2.txt  

and if you run:

rename "T\*.\*" "/\*.\*"  

Then, the files get changed to:

his is file 1.txt  
his is file 2.txt

Manohar Reddy Poreddy

Posted 2011-01-23T17:42:00.670

Reputation: 231

1

I was looking to svn rename a bunch of files with some common text. As I already had cygwin installed I ended up running bash:

bash-3.1$ for i in ipad_*; do svn rename $i ${i/ipad_}; done

I know TortoiseSVN sometimes prompts for common replacements but not in this case.

pfa

Posted 2011-01-23T17:42:00.670

Reputation: 11

0

Go to cmd.exe and type in:

REN "Radiohead*.mp3" "*.mp3"

(With Quotes)

Tobi

Posted 2011-01-23T17:42:00.670

Reputation: 191

That's probably because what you are trying to rename it to (*.mp3). The asterisk includes the string "Radiohead", so basically you take all the files beginning with "radiohead" and renames it to the same as before, thus no effect. – CB Du Rietz – 2014-06-25T11:33:24.517

True. If the filename changes it works, as in: REN Radiohead.log Mediahead.log – Manohar Reddy Poreddy – 2016-09-17T15:10:36.283

I just tested it. It does not work. Maybe due to the spaces in the file-names. (radiohead - 04 - testname.mp3) – Hennes – 2013-01-19T15:17:00.497

It didn’t work for me, either. – Scott – 2013-04-04T19:48:22.043

-2

There's plenty of software out available specifically for doing this with music files. One example I've used is Tag&Rename. If you're looking for a general utility to use with any type of file, I'm sure they exist as well. But I don't have any examples off the top of my head.

Ryan Bolger

Posted 2011-01-23T17:42:00.670

Reputation: 3 351