Get e-mails with new posts.

Web Site

Name Twister

If you need to rename a number of files in complicated ways, Name Twister can do it. (Name Twister replaces the Rename Regular Expression aka RenameRegEx shell extension.)

Get Name Twister Free

Name Twister displays a list where you can drag & drop files from anywhere in Windows. Then you can enter simple search & replace text (such as replace “cat” with “dog”) or more complex regular expressions.

Name Twister Screenshot

In the target expression, you can use $1 through $9 for groups you matched in the source expression.

Right-click on either expression field for a quick reminder of the most frequently-used elements. (This is usually easier than memorizing the sometimes arcane syntax of regular expressions.)

The dropdown combo boxes store their previous values so you can easily reuse previous expressions.

The Case-sensitive matching check box enables, of course, case-sensitive searches, which ensures that the text will only match if the case matches.

If you select the Replace all matches check box, every match in the source expression will be replaced with the target expression. If the check box is cleared, only the first match will be replaced.

If the Replace “#” with… check box is selected, any series of # characters in the target expression will be replaced by a number, starting with the number you enter.

You can resize the window any way you want and the controls will automatically resize themselves to use all of the space.

Regular Expressions

This documentation will be fairly brief and it assumes you have some knowledge of regular expressions. You can learn more on Microsoft’s .NET Regular Expressions page.

You use a regular expression to match a specific pattern of text, such as all words that begin with “b” or all text starting with 0 and ending with a period.

Regular Expression Syntax

. Matches any single character.
[ ] Indicates a character class. Matches any character inside the brackets (for example, [abc] matches “a”, “b”, and “c”).
^ If this metacharacter occurs at the start of a character class, it negates the character class. A negated character class matches any character except those inside the brackets (for example, [^abc] matches all characters except “a”, “b”, and “c”).
If ^ is at the beginning of the regular expression, it matches the beginning of the input (for example, ^[abc] will only match input that begins with “a”, “b”, or “c”).
- In a character class, indicates a range of characters (for example, [0-9] matches any of the digits “0” through “9”).
? Indicates that the preceding expression is optional: it matches once or not at all (for example, [0-9][0-9]? matches “2” and “12”).
+ Indicates that the preceding expression matches one or more times (for example, [0-9]+ matches “1”, “13”, “666”, and so on).
* Indicates that the preceding expression matches zero or more times.
??, +?, *? Non-greedy versions of ?, +, and *. These match as little as possible, unlike the greedy versions which match as much as possible. Example: given the input “<abc><def>”, <.*?> matches “<abc>” while <.*> matches “<abc><def>”.
( ) Grouping operator. The matching text can be referenced in the source expression with a backreference or in the target expression by a matching operator. Example: (\d+,)*\d+ matches a list of numbers separated by commas (such as “1” or “1,23,456”).
\ Escape character: interpret the next character literally (for example, [0-9]+ matches one or more digits, but [0-9]\+ matches a digit followed by a plus character). Also used for abbreviations (such as \a for any alphanumeric character; see table below).
\# If \ is followed by a number n, it matches the nth match group (starting from 0). Example: <{.*?}>.*?</\0> matches “<head>Contents</head>”.
$ At the end of a regular expression, this character matches the end of the input. Example: [0-9]$ matches a digit at the end of the input.
| Alternation operator: separates two expressions, exactly one of which matches (for example, T|the matches “The” or “the”).

Abbreviations

You can also use abbreviations, such as \d instead of [0-9].

\d Any decimal digit
\D Any non-decimal digit
\w Any word character
\W Any non-word character
\s Any whitespace character
\S Any non-whitespace character

Tips

Filename Conflicts

If you have a set of numbered files that you want to renumber, it’s possible that the filenames might “collide” during renaming. For example:

Current name New name
test1.txt test1.txt
test11.txt test12.txt
test2.txt test3.txt

If the source expression is test.+ and the target expression is test#.txt, Name Twister will display an error when it tries to rename test11.txt to test2.txt because test2.txt already exists.

The workaround is to modify the rest of the filename too, not just the numbers. In this example, you can change the target expression to test_#.txt. (Note the new underscore.)

Numbers After Groups

You might have a set of numbered files and when you get more than nine, you want to add zeroes so that the file names all have the same number of digits.

Current name New name
test1.txt test01.txt
test2.txt test02.txt
test3.txt test03.txt

(In this example, it’s easy to change test to test0, but if you have a more complicated file name, you might need an expression to match the part before the number.)

If you want to add a zero (0) before a number, you might try this:

Source: (t.+t)
Target: $10

That won’t work because “$10″ looks like you want the tenth group (which doesn’t exist). The trick is to use braces around the group number.

Source: (t.+t)
Target: ${1}0

Read more about Substituting a Numbered Group on Microsoft.com.

Group Names

If you have a complex expression with many groups, it can be difficult to remember that $4 is the year and $6 is the last name and $2 is the minute. Fortunately, you can name groups.

Filename: 20120526-1642 Camera 5 Studio backlot 1074a.png

Source: (?'yyyy'\d\d\d\d)(?'mm'\d\d)(?'dd'\d\d) (?'name'.+) (?'code'\d+a)(?'ext'\....)$
Target: ${name} (Code ${code}) - ${dd}${mm}${yyyy}${'ext'}

Read more about Substitutions on Microsoft.com.

Requirements

Name Twister runs on Microsoft® Windows® 7, Vista, XP Home and Professional. It requires .NET Framework 3.5. (Although it may work on other versions of Windows, it’s not guaranteed.)

History

2.0.6: Fixed some on-line help.
2.0.5: Fix enabling buttons after changing list of files.
2.0.4: CTRL+A selects all items in list. Add new combo box history items to top of list. Changed column names. Display “move” icon when dragging.
2.0.3: Update tooltip after applying changes.
2.0.2: “Delete” key removes a saved expression. Display in a tooltip the number of files renamed, not renamed, or conflicted. Fixed issue where files weren’t renamed after using a sequence resulted in no change.
2.0.1: Remember previous source and target expressions for future use. “Delete” key removes files from list.
2.0.0: Re-wrote RenameRegEx as Name Twister, a new application (instead of a shell extension).
1.10: Added support for folders, shortcuts, etc. Fixed some cases where the context menu command wouldn’t appear.