GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Various simple rename presets

metadata
regex

#1

The Rename dialog in Directory Opus lets you store presets which you can re-use to perform common rename tasks. It's also possible to import and export these presets to share them with other people.

Opus 12 example:

Older version example:

Listed below are some rename presets that I find useful.

I've included the regular expressions and wildcards here in case they are helpful examples for people new to regular expressions.

If you just want to use the presets and don't care how they work then you don't need to type them into Opus. Instead, I've attached a zip file with each preset saved as a .orp file.

To load a preset into your Rename dialog, make sure the dialog is in Advanced mode, then select Import... from the File menu. That loads the preset from disk but only temporarily. To add it to your personal list of presets, click the Add button above the list on the right and give it a name.

Here's what all the presets in this post do:

  1. Add - after number -- Regexp ([0-9]+) (.*) to \1 - \2

    03 Survivalism.wma -->
    03 - Survivalism.wma

  2. Add 1. Prefix -- Wildcard * to 1.*

    06 - The Fragile.wma -->
    1.06 - The Fragile.wma

  3. Add 2. Prefix -- Wildcard * to 2.*

    09 - The Big Come Down.wma -->
    2.09 - The Big Come Down.wma

  4. Count Files -- Regexp (.*)\.(.*) to [#].\2

    hello.jpg, there.jpg, etc. -->
    0001.jpg, 0002.jpg, etc.

  5. Make Safe Name -- Regexp (.*)([^-0-9a-zA-Z._]+)(.*)# to \1_\3

    Replaces all "unsafe" characters with underscores, so the filename is suitable for putting on a web server, for example. Everything except letters, numbers and '-' '_' and '.' will be replaced with '_'.

    2.11 - Ripe (With Decay).wma -->
    2.11_-_Ripe__With_Decay_.wma

  6. MCE Episode Rename -- Regexp .*(..)_(..)_(200.)_(..)_(..)_(..).dvr-ms to \3-\2-\1 - \4-\5.dvr-ms

    Used for sorting TV shows recorded with Media Center. Just keeps the date and time, in a nicer format, since I put the shows' names in their parent folders. Easily modified if you want to keep the titles, though.

    The Daily Show with Jon Stewart_More 4_25_04_2007_00_26_03.dvr-ms -->
    2007-04-25 - 00-26.dvr-ms

  7. Move to Artist Subdir -- Regexp ^([^-]+) - (.+)$ to \1\\\2

    The Sanderson Pitch - Dive (album version).mp3 -->
    The Sanderson Pitch\Dive (album version).mp3

  8. Move to Letter Subdir -- Regexp (.)(.+) to \1\\\1\2

    Gail_Porter_002_1024.jpg -->
    G\Gail_Porter_002_1024.jpg

  9. Move to Year-Album Sudir -- Regexp (.*) - ([0-9][0-9][0-9][0-9]) - (.*) to \1\\\2 - \3

    Audioslave - 2006 - Revelations -->
    Audioslave\2006 - Revelations

  10. Shooting Time -- Wildcard * to Birthday Party\{shootingtime|D#dd-MMM-yyyy} - {shootingtime|T#hh.mm} - [#].jpg

    (Opus 11 and earlier: Turn on Enable file information fields.)

    Inserts the EXIF shooting-time value into the names of photos. The "Birthday Party" part can be changed when the preset is used to create whatever subdirectory you want for the images, or removed completely if you don't want to move them as part of the rename.

    P1000291.JPG -->
    Birthday Party\07-Jan-2007 - 01.32 - 001.jpg

    Related thread: Set Created/Modified timestamps to EXIF Shooting Time

  11. Sort Music by Tags -- Wildcard * to {mp3artist} - {mp3year} - {mp3album}\{mp3track|#2} - {mp3title}.{ext}

    (Opus 11 and earlier: Turn on Enable file information fields.)

    Uses tag data inside of music files to generate their filenames and organise them into album folders.

    Track 02.wma -->
    John Coltrane - 1957 - The Ultimate Blue Train\02 - Moment's Notice.wma

  12. Strip Artist -- Regexp (.*) - (.*) - (.*) to \2 - \3

    Nine Inch Nails - 03 - Love Is Not Enough (Live At Rehearsals).flac -->
    03 - Love Is Not Enough (Live At Rehearsals).flac

  13. Strip Number -- Regexp (.*) - (.*) - (.*) to \1 - \3

    Nine Inch Nails - 03 - Love Is Not Enough (Live At Rehearsals).flac -->
    Nine Inch Nails - Love Is Not Enough (Live At Rehearsals).flac

  14. Strip Year from Album -- Regexp (.+) - [0-9][0-9][0-9][0-9] - (.+) to \1 - \2

    Red Hot Chili Peppers - 2006 - Stadium Arcadium - Jupiter -->
    Red Hot Chili Peppers - Stadium Arcadium - Jupiter

  15. Swap Various Artists -- Regexp (.+) - (..) - (.+) to \2 - \1 - \3

    David Bowie - 23 - I'm Deranged (reprise).wma -->
    23 - David Bowie - I'm Deranged (reprise).wma

opus9_various_rename_presets.zip (4.1 KB)


Move picture to subfolder with date name
Help needed, Spliting filenames into folders
Rename: Replace period(.) with Space
MS-DOS Batch Function - How To?
Script for inverting files names
Websafe renaming
HELP: delete asian (unicode) characters from file or folder
Rename Folder Help, plz!
Batch-edit ID3-Tags of MP3-Files
Regex help for MP3 name
Condensing multiple folders to one main named folder
Quickest way to trim characters from/rename multiple folders
Rename - remove everything in bracket
Removing Non English Characters From Titles
Suggestion for rename while using the meta panel
Rename Help with interesting difficult regEx patterns
Reg Exp gives Error 3
How to import/install rename scripts?
Meta Title to Filename
Web rename script? (percent url ascii encoding)
Button to rename files with funny characters?
Regular Expression ? What's wrong here?
Rename Function
Regular Expression ? What's wrong here?
Button to select files with same first 5 or so characters?
Rename files using their parent folder
Delete first word in filename
#2

[quote="evan.fotis"]For example I'd like this file:
"133_01_MALE-HEAD-PROF.jpg"
to be renamed into this:
"01_MALE-HEAD-PROF.jpg"[/quote]
There are a few ways you can do this.

Remove everything up to and including the first _ in each filename:

Old name: [^_]+_(.+)
New name: \1
Type: Regular Expressions

Remove the first 3 characters from the start of a filename:

Old name: ...(.+)
New name: \1
Type: Regular Expressions

In the last example the number of dots before the first bracket define how many characters to remove, so if you want to remove 4 characters you'd use ....(.+) instead, and so on.

You have to use VBScript for that, unless you can think up a way to do your rename using a single expression (which is often hard/impossible).

There's an example VBScript script in the forums that you can modify to suit your needs so the only thing you have to learn is VBScript's slightly different regular expression syntax.


#3

I try... :wink:

Insert text just before extension...
Old name: (.*)(\..*)
New name: \1_your_text\2
Type: Regular Expressions

Insert text after x characters...
Old name: (...)(.+)
New name: \1_your_text\2
Type: Regular Expressions

The number of dots under the first bracket define how many characters to keep before your text, so if you want to keep 4 characters you'd use (....)(.+) instead, and so on.


#4
  • Replace Dots with Spaces, except when surrounded by numbers:

    Here's a simple Rename question that comes up sometimes (and requires an unexpectedly complex answer):

    [quote="AlbatorV"]I need some help to replace dots by spaces only if previous/next character is letter.
    Directory.Opus.9.1.0.6.x86.exe -> Directory Opus 9.1.0.6 x86.txt[/quote]

    [quote="anjan_oleti"]I would like to replace the period(.) in filenames with Space; when it does not appear in between numeric digits.
    Directory.Opus.9.1.txt -> Directory Opus 9.1.txt[/quote]

    Zippo came up with the solution in his thread:

    Old Name: (.*)(([^0-9])\.|\.([^0-9]))(.*\..*)#
    New Name: \1\3 \4\5
    Type: Regular Expressions

    Or, if you want to make a button instead of using the Rename dialog:

    @NoDeselect
    Rename REGEXP PATTERN="(.*)(([^0-9])\.|\.([^0-9]))(.*\..*)#" TO="\1\3 \4\5"[/code]
    

    With Opus 12 you can simplify this slightly, as the ignore extension option means you don't have to worry about preserving the last dot. As a bonus, it now works properly with folder names:

    Old Name: (.*)(([^0-9])\.|\.([^0-9]))(.*)#
    New Name: \1\3 \4\5
    Type: Regular Expressions
    :ballot_box_with_check: Ignore Extensions

    You could probably also simplify it using regex asserts, or using a script, but the above works fine as-is.

  • Add spaces around dash (-) characters and collapse multiple spaces:

    Another solution by Zippo from the same thread. Here's how he described it: This flanks '-' characters with a space character on each side if the space character does not already exist. Additionally, multiple space characters are reduced to only one.

    (Note that there are two spaces near the end of the Old Name string.)

    Old Name: (.*)(([^ ])(-)|(-)([^ ])|  )(.*)#
    New Name: \1\5\3 \4\6\7
    Type: Regular Expressions
    

    Or, as a button:

    @NoDeselect
    Rename REGEXP PATTERN="(.*)(([^ ])(-)|(-)([^ ])|  )(.*)#" TO="\1\5\3 \4\6\7"
    
  • Add spaces around numbers:

    This is derived from the example above.

    Old name: (.*)(([^0-9 ])([0-9]+)|([0-9]+)([^0-9 ]))(.*\..*)#
    New name: \1\3\5 \4\6\7
    Type: Regular Expressions

    Or, as a button:

    @NoDeselect
    Rename REGEXP PATTERN="(.*)(([^0-9 ])([0-9]+)|([0-9]+)([^0-9 ]))(.*\..*)#" TO="\1\3\5 \4\6\7"
    

Rename: Replace period(.) with Space
#5

Wow! I can't believe I didn't' stumble on this post before. These presets are incredibly useful!

I have tried to tweak a couple of them to suit my needs. For the "Swap Artists" preset, I changed it so that it would just swap words between a dash (as long as there is only one dash). So for example, if I have a book named "Lewis Carroll - Alice in Wonderland.pdf" it would change it to "Alice in Wonderland - Lewis Carroll.pdf". So I tried the following:

Regexp (.+) - (.+) to \2 - \1

It works, but the problem is that the extension is also swapped, so that it results in:

"Alice in Wonderland.pdf - Lewis Carroll"

Is there anyway for me to change the code so that I can avoid swapping the extension?

Just in case anyone else is interested, solution can be found here:

(2017: Also note that with Opus 12 you can just turn on ignore extension to avoid having to worry about the file extension when changing the rest of the name.)


#7

(Dummy reply to fix a forum issue.)