Is there an OSX app/way to batch rename files via a purely text interface?

Many years ago - when I was a Windows user - I had an application which made renaming files an amazingly simple experience. You would select the files you wish to work with, and their filenames would appear within what was essentially a huge textarea. Imagine a text editor (such as TextEdit, Sublime Text, etc.) open to a document that simply lists all filenames, with each filename on a new line. With the files in this interface, you had your "standard" find/replace tools (CMD+F), as well as the ability to use REGEX. You could use the keyboard's arrows to move around the filenames without extra clicks or bulky interfaces. Modified filenames were highlighted with a different background and applying changes to all files was a simple CMD+S. Does something like this exist for OSX? // edit - to clarify: I'm aware of OSX's built-in bulk file renaming options in Finder, and software along the likes of NameChanger, Renamer, Automator, ABetterFinderRename, etc. I'm specifically looking for software with the kind of UI I described. // edit 2 - the original Windows software is called Oscar's Renamer: http://www.mediachance.com/free/renamer.htm

Yuriy Babenko asked Jun 24, 2015 at 23:13 Yuriy Babenko Yuriy Babenko 149 1 1 silver badge 6 6 bronze badges

Could you please give us the name of the Windows app? It's possible that there are already pages online full of people asking about a Mac version of that app by name.

Commented Jun 25, 2015 at 4:47

So when the program initially opened there was a new line separated list of the file names, and then after you modified them the program knew which line the original file was on and renamed it to whatever the corresponding line now reads?

Commented Jun 25, 2015 at 6:09 Do you have a screenshot of the Windows application, so people understand what to look for? Commented Jun 25, 2015 at 10:49

I've been trying to dig up the Windows version, but have so far come up blank. It has been a good 6-7 years.

Commented Jun 25, 2015 at 22:34

@forquare, that's generally correct, except you browsed to the folder containing the files to be renamed after opening the program, although (for me) it doesn't matter how/when the program discovers the files. The renaming interface (of a big textarea) is the key.

Commented Jun 25, 2015 at 22:35

8 Answers 8

Emacs can do this.

  1. Open Emacs
  2. C-x C-f and open the directory. It will open in dired-mode .
  3. M-x wdired-change-to-wdired-mode RET

You can now edit the filenames just as you asked. Pressing C-c C-c will end wdired-mode and perform the modifications.

wdired-change-to-wdired-mode is an interactive autoloaded Lisp function in `wdired.el'.

It is bound to .

(wdired-change-to-wdired-mode)

Put a Dired buffer in Writable Dired (WDired) mode.

In WDired mode, you can edit the names of the files in the buffer, the target of the links, and the permission bits of the files. After typing C-c C-c, Emacs modifies the files and directories to reflect your edits.

See `wdired-mode'.

answered Jun 27, 2015 at 17:25 Alan Shutko Alan Shutko 12.5k 2 2 gold badges 27 27 silver badges 27 27 bronze badges OS X comes with emacs for the terminal - GUI versions are also easily installed Commented Jun 27, 2015 at 18:20

If you're on OS X Yosemite (v10.10.x), Finder has a built-in way to batch rename files. Highlight all the files you want in Finder, hold down Control and click on one of them to bring up a right-click menu, and then click on "Rename x Files. ". You'll get a nice find-and-replace interface, no third-party software necessary!

answered Jun 24, 2015 at 23:57 6,262 5 5 gold badges 29 29 silver badges 54 54 bronze badges I'm aware of that feature, and it's absolutely not what I'm looking for. Commented Jun 25, 2015 at 0:54

Follow these steps:

  1. Install DiffMerge and gem install batch_rename (see README.md for details).
  2. In Terminal.app, cd to the directory which contains the files you wish to rename.
    (For convenience, I suggest to ⌘-drag the folder from the Finder into the Terminal window.)
  3. Type batch-rename and press Enter. This opens an interactive editor.
    The script will wait for you to close the editor. Then it will rename the files.

(Disclosure: I’m the author of the batch-rename tool.)

Edit: I liked OP’s problem so much that I’ve made my answer into a command-line tool for everyone’s convenience. To take advantage of the simplification, I have also rewritten my answer above.

I have uploaded the source to GitHub and published it as an installable gem on RubyGems.
Both are under a ISC license so feel free to send me issues and pull requests.

You can find my original answer below for reference.

2. cd to the proper working directory.

3. Run the following Ruby script:

#!/usr/bin/env ruby # encoding: utf-8 require 'shellwords' require 'tmpdir' Catalog = Struct.new(:time, :title, :file_name, :escaped_file_name) do def lines File.open(file_name).each.map(&:chop) end end CAPTION = "Batch rename - #< Dir.pwd >" DIFF_TMP_DIR = Dir.mktmpdir('batch-rename-') DIFFMERGE = '/usr/local/bin/diffmerge' catalogs = [:before, :after].map do |t| title = "# < t.capitalize >renaming" file_name = "#< DIFF_TMP_DIR >/#< title >.utf8" escaped_file_name = Shellwords.escape(file_name) Catalog.new(t, title, file_name, escaped_file_name) end `ls -A | tee #< catalogs.map(&:escaped_file_name).join(' >') >` args = catalogs.map.with_index do |c, i| ["-t#< i+1 >=#< c.title >", c.file_name] end system(DIFFMERGE, "-c=\"#< CAPTION >\"", *(args.flatten)) puts catalogs .map(&:lines) .reduce(&:zip) .select < |a| a.reduce(&:!=) >.map < |pair| pair.map(&Shellwords.method(:escape)) >.map < |a, b| "mv ##" > .join("\n") 
answered Jun 25, 2015 at 19:26 1,271 8 8 silver badges 14 14 bronze badges

For Sublime Text user, there is a package called SublimeFileBrowser that basically is dired in Sublime Text plus the all keyboard cursor movements trick of Sublime Text. You can pair with Text-Pastry or any other package that could help you manipulate the text easily.

answered Sep 30, 2016 at 14:49 186 1 1 silver badge 10 10 bronze badges

It's been a while since I have used it. But FileBuddy is designed to manipulate file names and a bunch of other stuff. Might be worth a look see.

answered Jun 24, 2015 at 23:49 Steve Chambers Steve Chambers 23k 3 3 gold badges 40 40 silver badges 60 60 bronze badges Thanks, but as with the other answer, totally not the interface I'm looking for. Commented Jun 25, 2015 at 0:56

In terminal, you have:

All have manual pages and volumes of text written on the internet in tutorials. I'd say, if you are into regex, the amount of time you'd need to adopt one of the unix tools to leverage text only renaming would be low and the return on investment high since you could then start automating even more challenging things than just file renaming.

If you really need a GUI - you could leverage any of the launchers such as LaubchBar or Alfred to kick things off and run your shell scripts.

answered Jun 29, 2015 at 23:46 239k 80 80 gold badges 427 427 silver badges 946 946 bronze badges

Here's YACLBFR(*) in perl based upon Larry Wall's simpler version of many years ago.

#!/usr/bin/perl # # rename - originally from Larry Wall: # Examples: # rename 's/\.orig$//' *.orig # rename 'y/A-Z/a-z/ unless /^Make/' * # rename '$_ .= ".bad"' *.f # rename 'print "$_: "; s/foo/bar/ if =~ /^y/i' * # # Author: Eric Engstrom ## use Getopt::Long qw(:config bundling); use Pod::Usage; use File::Basename; GetOptions('h|help' => \$HELP, 'n|dryrun' => \$DRYRUN, 'v|verbose' => \$VERBOSE, 'f|force' => \$FORCE ) or pod2usage(2); pod2usage(1) if $HELP; ($expr = shift) || pod2usage(2); if (!@ARGV) < @ARGV = ; chop(@ARGV); > for (@ARGV) < $was = $_; eval $expr; die $@ if $@; mkdirs($_); printf("%s%s >>> %s\n", $was, (length($was.$_) < 80 ? "" : "\n"), $_) if (($VERBOSE || $DRYRUN) && ! ($was eq $_)); warn "$_ already exists - not renaming $was\n" if ( ! $DRYRUN && ! $FORCE && -e $_ ); rename($was,$_) unless ($DRYRUN || $was eq $_ || (! $FORCE && -e $_)); >sub mkdirs($) < my $dir = dirname(@_); if (! -d $dir) < mkdirs($dir); print "making directory: $dir\n" if $VERBOSE; mkdir $dir unless $DRYRUN; >> ## __END__ =head1 NAME rename \- renames multiple files using perl expressions =head1 SYNOPSIS rename [options. ] perlexpr [file. ] =head1 DESCRIPTION B renames the filenames supplied according to the rule specified as the first argument. The argument is a Perl expression which is expected to modify the $_ string in Perl for at least some of the filenames specified. If a given filename is not modified by the expression, it will not be renamed. If no filenames are given on the command line, filenames will be read via standard input. For example, to rename all files matching *.bak to strip the extension, you might say rename 's/\e.bak$//' *.bak To translate uppercase names to lower, you'd use rename 'y/A-Z/a-z/' * =head1 OPTIONS -h --help brief help message -n --dryrun show what would be renamed, but does not rename anything -v --verbose be verbose during operation =head1 AUTHOR Eric Engstrom - email him as specified in the comments of this script Seriously adapted from a previous incarnation by Father (Larry) Wall. =head1 SEE ALSO mv(1), perl(1), perlre(1) 

(*) Yet Another Command Line Batch File Renamer.