Jump to content


Photo

Rename 3.2 (was RegEx): Rename or Batch Rename files or folders (supports Regular Expression, EXIF date and Yosemite)

rename batch regular expression EXIF

  • Please log in to reply
51 replies to this topic

#1 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 03 April 2013 - 05:22 AM

Overview

  • Rename a file or a folder selected in Finder or in Alfred
  • Batch rename files or folders using Regular Expression
  • Add additional steps such as find and replace, remove space, remove diacriticals, capitalize, add current date, file modified date, custom number sequence, EXIF original date etc.
  • Quick look to preview all the new names
  • Recent Expressions
  • Presets, including default ones ready to be used

Triggering

  • keywords ren or regex - main workflow keyword
  • keywords ren? or regex? - read about the workflow
  • Hotkey - show Alfred with the keyword ren
  • Hotkey - use the last expression with no interaction
  • File Action - rename files or folders selected in Alfred file browser

How to Use

Rename Only

You can use the workflow to rename a single file without using a regular expression, like in Finder:

  • Select a single file in the Finder (or in Alfred file browser)
  • Type the keyword ren
  • Type the new filename e.g. new name.txt

You can optionally use modifiers and filename additions (see below).

Rename with Regular Expression

Here is a command line with all features, including the optional ones, as explained below:
 

regular expression@new filename $d-$m-$y ###[1]{find@@replace}{-modifiers}

Step by step:

(1) Type the regular expression to group elements of the previous filename:

^([ˆ ]+) (.*)\.(.*)

The workflow will group using $1, $2, $3 and so on. Later you can use them to build a new filename.

(2) When the regular expression is finished type then an at sign at the end:

^([ˆ ]+) (.*)\.(.*)@

(3) After the at sign type the new filename (here you can use the groups formed in the first step):

^([ˆ ]+) (.*)\.(.*)@$1.$3

(4) Optionally add current date or any other filename constants (read below about them):

^([ˆ ]+) (.*)\.(.*)@$1 $d-$m-$y.$3

(5) Optionally add a custom sequence of numbers e.g. with two leading zeros starting at one (read how to build a custom sequence below):

^([ˆ ]+) (.*)\.(.*)@$1 $d-$m-$y ##[1].$3

(6) Optionally find and replace characters in the original filename utilizing the syntax {find@@replace}:

^([ˆ ]+) (.*)\.(.*)@$1 $d-$m-$y ##[1].$3{_@@-}

(7) Optionally utilize one of the modifiers (read about them below) to e.g. set all letters to lowercase:

^([ˆ ]+) (.*)\.(.*)@$1 $d-$m-$y ##[1].$3{_@@-}{-l}

Note that it is important to keep the modifiers at the very end of the command and enclosed by {}, using or not find and replace.

If all you need is a simple find and replace you can use the following simplified command:

find@@replace{-modifiers}

Whether using the regular expression or only the simple find and replace you can always preview the new filenames pressing SHIFT key:

rename3_2.png

Modifiers

  • -d to remove diacriticals
  • -s to remove space
  • -c to Capitalize Name
  • -t to Title name
  • -u to UPPERCASE
  • -l to lowercase
  • -_ to replace underscore to space
  • -b to replace space to underscore

Use one or more at the very end of the command enclosed by {}, for example:

(.*)\.(.*)@$1.$2{-s-u}
-@@_{-u}

New Filename Constants

You can add the following constants to the new filename:

Current Date

  • $d = day e.g. 02
  • $m = month e.g. 04
  • $mm = month e.g. April
  • $y = year e.g. 2013
  • $h = hour e.g. 02
  • $n = minutes e.g. 54
  • $s = seconds e.g. 30

Date Created

  • $cd = day e.g. 02
  • $cm = month e.g. 04
  • $cmm = month e.g. April
  • $cy = year e.g. 2013
  • $ch = hour e.g. 02
  • $cn = minutes e.g. 54
  • $cs = seconds e.g. 30

Date Modified

  • $mod = day e.g. 02
  • $mom = month e.g. 04
  • $momm = month e.g. April
  • $moy = year e.g. 2013
  • $moh = hour e.g. 02
  • $mon = minutes e.g. 54
  • $mos = seconds e.g. 30

EXIF Original Date

This is the date and time when the image was originally captured by the camera.

  • $ed = day e.g. 02
  • $em = month e.g. 04
  • $emm = month e.g. April
  • $ey = year e.g. 2013
  • $eh = hour e.g. 02
  • $en = minutes e.g. 54
  • $es = seconds e.g. 30

Image Dimensions

  • $iw = width in pixels
  • $ih = height in pixels

Sequence

You can add a number sequence to the new filename by utilizing # (each one represents a leading zero) followed by the start number enclosed in brackets e.g. ###[1] which means 3 leading zeros starting at 1.

Create New Folder and Move Files

You can also use the regular expression to create a new folder and move the file(s) there.

Utilize a forward slash ("/") before the new name:


(.*)@$m-$y/file.png

A new folder will be created based on current month ($m) and year ($y) and the file will be renamed and moved to there.

Recent Expressions and Presets

To make things faster the workflow:

  • Display the last used expression
  • In Recent Expressions there are a list of the last 40 used expressions; note that you can alo use a shortcut to access them: just type a single at sign (@)
  • In Presets there are some ready to use expressions a long with the user favorites ones; note that you can alo use a shortcut to access them: just type a single hash sign (#)

rename3.png

The workflow saves the last used regular expression in the main workflow menu, a list of recent regular expressions and a list of Presets.

To add a Recent expression to Presets just type a plus symbol followed by the preset name: +For My Videos

While in Presets just type a minus symbol “-“ to remove from Presets.

Download Version 3.2

  • Release date 25 Aug 2014
  • OSX 10.9.2
  • Alfred 2.4 or later is required
  • Download Now

What's new?

  • 3.2 Yosemite support
  • Changed workflow name to only Rename
  • EXIF Original Date (to use as a filename constant)
  • Up to 10 times faster to process and even faster to rename
  • Included the keyword ren as an alternative to the regex
  • Recent Expressions shortcut: type a single @
  • Presets shortcut: type a single #
  • New Picture Preset
  • Improved Last Used feature
  • UI refinements, including new icons
  • New Help
  • Filename case procedure improved
  • Fixed second leading zero constant

Workflow version history here.


Edited by Carlos-Sz, 25 August 2014 - 10:15 PM.

  • Enhorn, bevesce, Benzi and 2 others like this

#2 Enhorn

Enhorn

    Member

  • Member
  • PipPip
  • 26 posts
  • LocationStockholm, Sweden

Posted 03 April 2013 - 06:09 AM

This looks amazing and almost to good to be true, but the download link doesn't work for me. :-(


Edited by Enhorn, 03 April 2013 - 06:15 AM.

  • 2b3f6b6b@anon.leemail.me likes this

#3 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 03 April 2013 - 06:41 AM

This looks amazing and almost to good to be true, but the download link doesn't work for me. :-(

 

Fixed. Thanks.

 

You can do the basic to extract text and group it to use later. 

 

For what I use to do it works well and the preview helps a bit.

 

https://dl.dropbox.c....alfredworkflow



#4 Enhorn

Enhorn

    Member

  • Member
  • PipPip
  • 26 posts
  • LocationStockholm, Sweden

Posted 03 April 2013 - 07:50 AM

Thanks. Excellent! :-D



#5 Ramiro Araujo

Ramiro Araujo

    Member

  • Member
  • PipPip
  • 81 posts

Posted 03 April 2013 - 03:06 PM

This is great!!!



#6 werkzeugh

werkzeugh

    Newbie

  • Member
  • Pip
  • 3 posts

Posted 03 April 2013 - 06:24 PM

great !

 

wanted to  write a similar thing, but starting with alfreds multi-file selection, but it would have lacked a way to enter a regex in the next step



#7 raguay.customct

raguay.customct

    Advanced Member

  • Member
  • PipPipPip
  • 396 posts
  • LocationTak, Thailand

Posted 04 April 2013 - 07:58 AM

So much for NameMangler. This is much easier and faster for me!



#8 hzlzh

hzlzh

    Member

  • Member
  • PipPip
  • 177 posts

Posted 04 April 2013 - 08:23 AM

Using regex is so nice.


Share on [Alfred Workflow List](Un-offical) : www.AlfredWorkflow.comSubmit Workflows | Workflow Searcher


#9 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 04 April 2013 - 04:55 PM

This is great!!!

 

 

great !

 

wanted to  write a similar thing, but starting with alfreds multi-file selection, but it would have lacked a way to enter a regex in the next step

 

 

So much for NameMangler. This is much easier and faster for me!

 

 

Using regex is so nice.

 

Great! While handling some files within Finder Alfred is much faster to use indeed.



#10 raguay.customct

raguay.customct

    Advanced Member

  • Member
  • PipPipPip
  • 396 posts
  • LocationTak, Thailand

Posted 05 April 2013 - 12:19 PM

I am typing almost the same expression several times. Maybe add a bookmarking/history function to reuse past regexp strings. That would be great. But, I know more PHP than Applescript.



#11 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 05 April 2013 - 05:27 PM

I am typing almost the same expression several times. Maybe add a bookmarking/history function to reuse past regexp strings. That would be great. But, I know more PHP than Applescript.

 

Great idea. I’ll add the feature. Thanks.



#12 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 05 April 2013 - 08:38 PM

I am typing almost the same expression several times. Maybe add a bookmarking/history function to reuse past regexp strings. That would be great. But, I know more PHP than Applescript.

 

And here is a new version with a History of regular expressions used: link



#13 raguay.customct

raguay.customct

    Advanced Member

  • Member
  • PipPipPip
  • 396 posts
  • LocationTak, Thailand

Posted 06 April 2013 - 03:51 AM

And here is a new version with a History of regular expressions used: link

Perfect!!! Thanks a lot. This is now my only way to rename files. 

 

Question: Is it going to record all sessions? It might be good to have a way to edit them or mark some as favorites that are shown at the top. Sorry, I love to brain storm! It's the engineer in me.



#14 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 06 April 2013 - 05:04 AM

Perfect!!! Thanks a lot. This is now my only way to rename files. 

 

Question: Is it going to record all sessions? It might be good to have a way to edit them or mark some as favorites that are shown at the top. Sorry, I love to brain storm! It's the engineer in me.

 

RIght now it will record everything but there are two things I’m considering: limit to 50 entries and/or a Favorite system.

 

By the way, I’m already testing Alfred File Action. :)


  • twinpeaks likes this

#15 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 06 April 2013 - 07:16 AM

One more thing is coming: the recent regular expression list is part of the main workflow interface with a drill-down alike menu interface. Something like this:

 

regex_rec2.png


Edited by Carlos-Sz, 06 April 2013 - 04:35 PM.


#16 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 06 April 2013 - 04:35 PM

Version 0.94 beta is out:

  • Alfred File Action
  • Improved and easy to use Recent Regular Expressions list
  • Hotkey to be used after selecting files or folders in Finder

 

Favorite Expressions coming soon:

 

regex_fav.png


Edited by Carlos-Sz, 06 April 2013 - 11:38 PM.


#17 arjunrc

arjunrc

    Member

  • Member
  • PipPip
  • 49 posts

Posted 07 April 2013 - 10:07 PM

Hi, lovely plugin. I am however facing a problem

I have a folder called "foo". Inside it I have a whole bunch of jpg files. I am trying to rename them to png (just for testing)

 

I selected the files, invoked alfred and typed

regex (.*).jpg@$1.png

 

 the preview showed perfectly but it keeps saying "can't yet rename files" - the only way I can get it to work is to not put any characters after .* like 

regex (.*)@$1.png

- which will make it .jpg.png - not what I want.

 

Any ideas?


Edited by arjunrc, 07 April 2013 - 10:08 PM.


#18 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 07 April 2013 - 10:46 PM

Hi, lovely plugin. I am however facing a problem

I have a folder called "foo". Inside it I have a whole bunch of jpg files. I am trying to rename them to png (just for testing)

 

I selected the files, invoked alfred and typed

 

 the preview showed perfectly but it keeps saying "can't yet rename files" - the only way I can get it to work is to not put any characters after .* like 

- which will make it .jpg.png - not what I want.

 

Any ideas?

 

 

Right now the workflow tries to check if the extension matches* to avoid an user mistake such as wrong extension or no extension at all.
 
One problem I thought about: if the user wants .jpg instead of .jpeg or .txt instead of .md. Maybe a command such as $x[.png] to force the new extension.
 
However, I think the default behavior is safer.
 
There is a solution though and I will implement in one way or another.
 
Thank you for your feedback! 
 
* this checking need to be improved as you example showed.

Edited by Carlos-Sz, 07 April 2013 - 10:48 PM.


#19 arjunrc

arjunrc

    Member

  • Member
  • PipPip
  • 49 posts

Posted 07 April 2013 - 11:07 PM

Carlos, thank you  for your note - given that this is a regex renamer, I think it would be better to take off this limitation (novice users will likely not use a regex in the first place). I took a look at regex_01.scpt - I removed the following check

 or _New_P does not end with theExt

and it seems to be doing exactly what I want 

 

Thanks!

 

PS: The preview function is excellent !


Edited by arjunrc, 07 April 2013 - 11:09 PM.


#20 Carlos-Sz

Carlos-Sz

    Community Hero

  • Member
  • PipPipPip
  • 800 posts

Posted 08 April 2013 - 12:50 AM

Carlos, thank you  for your note - given that this is a regex renamer, I think it would be better to take off this limitation (novice users will likely not use a regex in the first place). I took a look at regex_01.scpt - I removed the following check

and it seems to be doing exactly what I want 

 

Thanks!

 

PS: The preview function is excellent !

 

 

Great!
 
Maybe you're right about the extension.
 
Anyway, a file without an extension at all could trigger some alert though… :)




Also tagged with one or more of these keywords: rename, batch, regular expression, EXIF

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users