How can I mass rename files?

126

48

I've got a bunch of files named with a the pattern 99 - DescriptiveName.txt and I'd like to remove the number from the front so I just have DescriptiveName.txt.

How can I do this? Can I do it from the command line or is there a utility that can do this?

BIBD

Posted 2009-07-30T20:31:17.027

Reputation: 1 506

See @IvanRF answer for a mass renaming tool that just does renaming and is super easy to use : https://superuser.com/a/730292/163741

– Benj – 2019-11-16T22:13:57.573

Answers

94

I know in your title you say "in dos" but I get the impression you are just looking for a way to do this and are wondering if that is the best way.

The absolute best tool I have found for this is Bulk Rename Utility.

Bulk Rename Utility

It isn't a command line tool, but they do have a command line version if you really want to use it that way.

I've used the GUI version a lot, and it is very powerful, very fast and extremely easy to use.

Oh, and it is FREE for personal use.

Jim McKeeth

Posted 2009-07-30T20:31:17.027

Reputation: 4 907

Unfortunately the tool isn't free for commercial use :( – AntonK – 2017-10-28T08:47:49.383

That is why I said it was free for personal use. – Jim McKeeth – 2017-10-30T21:16:36.143

2This is super-quick tool. It solved my 6.000 files issue in seconds, using several search-and-replace logics. Is like using Notepad++ but editing thousands of files. A great solution, thanks! – Peanuts – 2018-07-25T19:06:04.180

60

A small PowerShell script:

$args | Rename-Item -NewName { $_.Name.ToLower() -replace '\d+ - ' }

Combined with more complex regular expressions, this might become something like:

ls | Rename-Item -NewName {$_ -replace '(\d+) - (.*).mp3', '$2 - $1.mp3' }

Which turns things like '01 - Beginning.mp3' into 'Beginning - 01.mp3'.

Use the -WhatIf parameter on Rename-Item to check renames before you issue them.

Joey

Posted 2009-07-30T20:31:17.027

Reputation: 36 381

Does replace not require two string expressions? The second one has two, the first one does not. ... -replace '\d+ - ',''. Also, I believe the first one is better, simply stripping off the beginning using regex. Though I believe you should include the ^ anchor at the beginning of the expression so it only matches names beginning with numbers. – Xalorous – 2016-08-08T15:54:48.527

1@Xalorous: Well, you could simply try it out. -replace can have just one argument on the right side, in which case the second one is implicitly the empty string. – Joey – 2016-08-08T20:00:41.957

This saved me .. Bulk Rename Utility just crashes now and I tried so many other solutions. This is way better for people who are comfortable with regexp. Thank you so much !! – Inkh Su Tesou – 2018-08-06T20:03:28.183

1@sysrqb, please research a little more. – Joey – 2014-01-14T09:51:42.760

24

AntRenamer makes it quite easy to define a pattern of renaming; there are plenty of ones already prepared (and it gives a preview of the actions):

AntRenamer

Free for personal and commercial use.

Gnoupi

Posted 2009-07-30T20:31:17.027

Reputation: 7 909

24

If you really want to use the windows command line (if you don't want to download something), you could do it like this:

dir /B > fileList.txt
for /f "tokens=1,2,3" %i in (fileList.txt) DO ren "%i %j %l" %l

The first line outputs the list of files into a file called fileList.txt. The second line separates each of the names in the list into 3 parts, the #, the "-" and the rest of the name. For each of those it does the rename command.

zdan

Posted 2009-07-30T20:31:17.027

Reputation: 2 732

2Remove the first line to simplify it and do: for /f "tokens=1,2,3" %i in ('dir /B') DO ren "%i %j %l" %l – None – 2015-01-07T18:38:32.633

I know this is old but it is still a solid answer -- only the %l (%L) should be %k (%K) [tokens increment from %i (%I) so I, J, K...] – Donald Byrd – 2018-06-18T03:04:31.317

19

old school:

You can do a DIR and redirect the output to a file, as in DIR *.TXT >TEMP.BAT

Then use an editor to take out what you don't need and modify the parts you do need. Add an "@echo off" as the top line, save it and run it.

WireGuy

Posted 2009-07-30T20:31:17.027

Reputation: 1 681

I got this page reference from an old-school doctorate in this: http://www.dostips.com/DosCommandIndex.htm; It is amazing what you can do with (good?) old DOS!

– nik – 2009-08-07T17:28:23.623

17

Another option: Massive File Renamer

It allows to easily rename multiple files and file extensions. It's very fast and simple!

For advanced users and developers, it is possible to use regular expressions.

See it in action:

enter image description here

IvanRF

Posted 2009-07-30T20:31:17.027

Reputation: 827

1Btw how can we select it to open all the files within subfolders? I've got a root folder with roughly 50 subfolders (recursively) and multiple files within them. – Pacerier – 2015-11-11T20:23:59.607

1@Pacerier I think the Java file chooser does not allow that. I had the idea of allow selecting a folder and recursive search can be included. I will note that and add it in a future release! – IvanRF – 2015-11-11T20:34:35.643

1Killer one, took me 4 seconds to understand how it works, 8 seconds to type the regex, took 1 sec to rename thousands of files. Super nice and easy, thanks ! – Benj – 2019-11-16T22:12:27.057

13

I use Total Commander's multi-rename tool (ctrl+M) for things like this. Their useful tool, one of too many to count, is easy to use, and can also employ regular expressions and templates if necessary. Oh, and it obviously gives you a preview before making any changes.

This is the third or fourth question I've answered recommending Total Commander... I should be getting a commission from them ;-)

Yuval

Posted 2009-07-30T20:31:17.027

Reputation: 2 022

11

The tool that I've been satisfied with is ReNamer. It supports also the saving of renaming rules, which has been useful to me, as I many times do the same renamings.

Below is an example of how to delete text before the first dash, but there are loads of other rules you can define.

enter image description here

Esko Luontola

Posted 2009-07-30T20:31:17.027

Reputation: 465

5

I've used Free Commander Portable (freeware) for this to good effect:

  1. Select or Navigate to the files or directories to rename
  2. Press [Ctrl-M] (or File > Multi-rename)
  3. fill out the fields as makes sense for your circumstance
  4. verify the preview shows what you expect
  5. Go!

matt wilkie

Posted 2009-07-30T20:31:17.027

Reputation: 4 147

4

For advanced users and developers, I would suggest RegexRenamer.

RegexRenamer screenshot

Pro's:

  • Very simple UI;
  • Regular expressions that the developers familiar with;
  • GPLv2;

Con's:

  • It's not a command line! :)

bytebuster

Posted 2009-07-30T20:31:17.027

Reputation: 611

Could not make it work recursively for all subfolders of the selected folder! – Luckylooke – 2018-09-13T09:51:59.550

3

The easiest way would be to use Rename Master.

Kevin Panko

Posted 2009-07-30T20:31:17.027

Reputation: 6 339

3

Here's a command-line solution --- a Java program I wrote specifically to make it easy to work with "patterns" in filenames. It's free and open source, so feel free to modify it:

RenameWand
http://renamewand.sourceforge.net/

Some relevant usage examples:

Drop everything before the "-" in the filename:

java -jar RenameWand.jar  "<a> - <b>"  "<b>"

Prepend a 3-digit number to the filename, sorting by last-modified time:

java -jar RenameWand.jar  "<a>"  "<3|#FT> <a>"

Rearrange parts of the filename, and change case:

java -jar RenameWand.jar  "<album> - <artist> - <song>.<ext>" 
                          "<artist.upper> <album.title> - <song>.<ext.lower>"

Zach Scrivena

Posted 2009-07-30T20:31:17.027

Reputation: 131

3

I discovered RenPhoric about a month ago. Superb. And it's free.

No complicated interface and I was quickly able to rename exactly as I wanted. Regular Expression capable. Haven't used anything else since.

Umber Ferrule

Posted 2009-07-30T20:31:17.027

Reputation: 3 149

2

I like Cylog’s WildRename. It is powerful, yet easy to use, and has a lot of features:

  1. fast
  2. string manipulation
  3. counters
  4. wildcards
  5. regular expressions
  6. substitution
  7. case-conversion
  8. logging
  9. simulation (show the results without actually applying them)

enter image description here

Synetech

Posted 2009-07-30T20:31:17.027

Reputation: 63 242

2

Like @zdan above, I did this by command line (using "cmd.exe" in Windows). It took some tinkering for my particular case, but a little research solved it.

Like zdan, I output the list to a TXT file, then used tokens and delims to rename the files accordingly. In my case, I started out with a list of files named like so:

name-01-02-2012.csv

I wanted the file date portion to be in y/m/d order, with the "name" part at the end so it would read like this:

2012-01-02-name.csv

To do this en-masse, I used the following code. Note that when doing it this way, ALL parts of the filename are considered, including the extension of ".csv". That goofed me up the first time around.

dir /B > fileList.txt
for /f "tokens=1,2,3,4,5 delims=-." %i in (fileList.txt) DO ren "%i-%j-%k-%l.%m" %l-%j-%k-%i.%m

The tokens are the "parts" of the filename, the delims are the separators. Note that in my case, I had 2 delimiters (a dash and a dot).

I personally don't care for the "Bulk Rename" app. As others have mentioned, the GUI is atrocious and not very intuitive. With a little research and simple coding, these things can be done much mroe efficiently and quickly.

gtr1971

Posted 2009-07-30T20:31:17.027

Reputation: 151

2

Funny name and command line tool very powerful, very fast and extremely easy to use. "Find And Replace Text" FART http://fart-it.sourceforge.net/ WORKS GREAT! can rename words in txt files too.

USAGE

Usage: FART [options] [--] <wildcard>[,...] [find_string] [replace_string]

Options:
 -h --help          Show this help message (ignores other options)
 -q --quiet         Suppress output to stdio / stderr
 -V --verbose       Show more information
 -r --recursive     Process sub-folders recursively
 -c --count         Only show filenames, match counts and totals
 -i --ignore-case   Case insensitive text comparison
 -v --invert        Print lines NOT containing the find string
 -n --line-number   Print line number before each line (1-based)
 -w --word          Match whole word (uses C syntax, like grep)
 -f --filename      Find (and replace) filename instead of contents
 -B --binary        Also search (and replace) in binary files (CAUTION)
 -C --c-style       Allow C-style extended characters (\xFF\0\t\n\r\\ etc.)
    --cvs           Skip cvs dirs; execute "cvs edit" before changing files
 -a --adapt         Adapt the case of replace_string to found string
 -b --backup        Make a backup of each changed file
 -p --preview       Do not change the files but print the changes

user212780

Posted 2009-07-30T20:31:17.027

Reputation: 1

Yes, -f option, as listed. – user1016274 – 2017-09-03T12:47:17.260

Some more details? Does it rename files? – vonbrand – 2013-03-30T20:38:15.440

2

Multi rename script is a open source alternative to Total Commanders Multi Rename tool which you could drive via script. It can use TC plugins for metadata information.

https://code.google.com/p/multi-rename-script/ http://multi-rename-script.googlecode.com/svn/trunk/docs/res/MRS.PNG

majkinetor

Posted 2009-07-30T20:31:17.027

Reputation: 510

2

@echo off
setlocal enabledelayedexpansion
set X=5
set FOLDER_PATH=.
pushd %FOLDER_PATH%
for %%f in (*) do if %%f neq %~nx0 (
    set "filename=%%~nf"
    set "filename=!filename:~%X%!"
    ren "%%f" "!filename!%%~xf"
)
popd

save this in a batch file and run

bbm123

Posted 2009-07-30T20:31:17.027

Reputation: 1

This is good, but how may I be able to make the X a variable (pass as a parameter)? – Kangkan – 2015-06-02T15:31:11.760

@Kangkan like this: set /p "X=Enter the value for X: " – Kidquick – 2018-04-12T14:51:10.783

1

I use Blackboard to administer courses in a University. When I download an assignment in mass (in Blackboard, click top of grading column, then "assignment file download" Blackboard adds a bunch of extra stuff to the file name -often making the file name too long to be valid on Windows.

Here's what they look like:

Recitation20Assignment_studentname_attempt_2013-03-01-20-03-09_Exercise28129.docx

And this is what I wanted

studentname.docx

So I used the approach that @zdan and @gtr1971 advised, by opening a command window on the folder with the files inside (CMD.EXE). Then run this command to put all file names in a document.

dir /b >filelist.txt

Edit the document and remove folder names, etc.

Use this command to replace the Blackboard added filename stuff with just the username and file extension.

for /f "tokens=1,2,3,4,5,6 delims=_." %i in (filelist.txt) do ren "%i _%j_%k_%l_%m.%n" %j.%n

Hope this helps someone else as well.

Webmentorman

Posted 2009-07-30T20:31:17.027

Reputation: 1

1

Here's another simple program called File Attribute Changer that you can use to rename files. It's a portable program, so you can carry it on a USB drive.

http://www.softpedia.com/get/Desktop-Enhancements/Other-Desktop-Enhancements/File-Attribute-Changer.shtml

Brian

Posted 2009-07-30T20:31:17.027

Reputation: 1

1

I have developed a hybrid JScript/batch command line utility called JREN.BAT that can rename files or folders by performing a regular expression search and replace on the names. It is pure script that will run natively on any Windows machine from XP forward. Full documentation is embedded within the script.

Assuming JREN.BAT is in your current directory, or better yet, somewhere within your path, then your rename task becomes trivial.

jren "^\d+[ -]+(.+)\.txt$" "$1" /i

or

jren "^\d+[ -]+(?=.+\.)" "" /fm "*.txt"

There are many options, including the /S option that recursively performs the rename on sub-directories.

dbenham

Posted 2009-07-30T20:31:17.027

Reputation: 9 212

0

If you need serious power and are willing to shell out the money... PowerGrep is one of the most powerful and versatile tools on the market... you can rename almost anything with PowerGrep... even binary search and replace... it's created by RegEx Guru, Jan Goyvaerts.

enter image description here

Eddie B

Posted 2009-07-30T20:31:17.027

Reputation: 909

This utility is insanely expensive... – Wizard79 – 2015-08-08T18:30:01.833

You can use it free indefinitely... however, its worth it... I use it all the time. – Eddie B – 2015-08-08T18:31:36.510