79

Mass Renaming Directories And Files Using Total Commander


Posted by Artem Russakovskii on March 12th, 2008 in Programming, Technology

Updated: September 16th, 2012

If you're like me, you constantly move and rename files and directories. You are also an extremely productive person with evangelical ideals of making every task as efficient as it can be. In this tutorial, I will use my favorite must-have file manager called Total Commander (formerly, Windows Commander) and its brilliant Multi-Rename Tool.

You can download a shareware version of Total Commander at www.ghisler.com. I encourage you to buy it after you try it as it'll soon become an integral part of your life. I've been using it for more than 10 years now and seriously can't imagine my computer without it.

Now for some quick tasks I'd like to accomplish using the Multi-Rename Tool in under a minute each that would otherwise take me ages (also being quite boring and tedious). In my example, I'm going to use 5 files, but feel free to extend it to any number – multi is multi after all. The tool supports regular expressions (regex) to execute more advanced operations.

And the sample files are:

vac-sick-leave request form 03-10-08.xls
vac-sick-leave request form 05-30-07.xls
vac-sick-leave request form 10-16-07.xls
vac-sick-leave request form 11-22-07.xls
vac-sick-leave request form 12-19-07.xls

I fire up Total Commander, highlight the files using the gray *, right clicking and dragging on the names, or pressing Insert – the possibilities are endless, and fire up the Multi-Rename Tool from the Files menu (or just Ctrl-M). Here's what the screen looks like now:

image

Now for some tasks. I find it better to show the capabilities of this tool in examples, rather than boring descriptions. You can find a full manual in Appendix A.

Task #1. Rename all files replacing 'vac' with 'vacation'.

Fill the boxes as follows:

Search for: vac
Replace with: vacation

Notice how the New name column changes instantly as you type to show the resulting file names.

image

Now you can press Start to make the changes final. Have no fear: there's an Undo button that will undo the last rename operation in case you made an error, even if you close and reopen the Multi-Rename Tool. You can also press the little button to the left of Start, which will reload the newly renamed filenames into the tool for further manipulations.

This solution is going to work fine in this case, but it's not going to work for all possible cases. For example, if the file name were vac-sick-evacuation request form 03-10-08.xls, the resulting filename would be vacation-sick-evacationuation request form 03-10-08.xls. In order to fix this, I will use a simple regular expression:

Search for: ^vac\b
Replace with: vacation
RegEx: check

^ would match only if vac is in the beginning of the filename and \b signifies a word boundary, meaning it wouldn't match vaca or vac3, but would match vac- or vac$. You can find the information about regex from the Total Commander manual in Appendix B at the end of this article.

Similarly, to replace all spaces with dots (replacing consecutive spaces with just 1 dot), you can enter:

Search for: \s+
Replace with: .
RegEx: check

\s – the space character, followed by +, will match 1 or more consecutive spaces.

image

Task #2. Change dates from US format MM-DD-YY to YYYY-MM-DD.

Search for: (\d{2})\-(\d{2})\-(\d{2})
Replace with: 20$3-$1-$2
RegEx: check

\d will match a digit, \d{2} will only match when 2 consecutive digits are seen, the dash symbol doesn't need to be escaped with \ in this case but it's usually a good practice to do so because it has a special meaning in regex. Finally, the parentheses signify that I want to remember what I matched and put it into $1, $2, and $3 – special variables called backreferences. As you can see, I use these backreferences in the replacement string.

image

Task #3. Number the files with a 2 digit counter, starting from 00.

Rename mask: file name: [C]. [N]
Define counter (C) Start at: 0
Define counter (C) Step by: 1
Define counter (C) Digits: 2

image

In this case, I've used a special [C] variable (this is unrelated to regex) that stands for counter and customized the counter setup. You can see some other useful variables in the screenshot.

Task #4. Rename 4 letter extensions into 3 letter ones (Excel 2007 xlsx -> Excel 2003 xls).

Let's say  now that my files have a .xlsx extension that was introduced in Excel 2007. There are actually a few ways I can think of renaming them in Total Commander, the easiest being selecting all files, pressing Shift-F6 (inline rename) and then entering *.xls. BAM! All files are now .xls. The problem is that this wouldn't work if I had a mix of .docx and .xlsx files, for instance. Another solution would be to use regex, but I want to try something different. Here goes:

Extension: [E1-3]

image

This approach replaces file extensions with the extension sub-string [1-3].

There are plenty of other tasks Total Commander lets me accomplish very efficiently, like dealing with archives, files in subdirectories, checksums, copying lists of files to clipboard, comparing directories, FTPing, searching, etc, etc, etc. Maybe I'll write about them some day. So go out there, download it, and I guarantee it will change the way you think of file management forever.

 

Appendix A. Total Commander Multi-Rename Tool manual.

With this dialog box, you can rename a list of files selected in Total Commander. Instead of * and ? wildcards, this function uses placeholders in brackets []. The new names are immediately shown in the result list, but the files are not renamed until the Start! button is pressed.

Field    Description

Rename mask: file name
    With this field, you can create a definition for a new file name. The buttons below allow to insert place holders for the previous name, parts of the name, a counter, or file date/time. Place holders are always in brackets [ ], while all other letters (without brackets) will be placed in the new name without a change.
    See below for a description of all available placeholders! Use Shift+Del to remove no longer wanted entries from the list.

Extension    Definition string for extension. In principle, all placeholders can be added to either of the two definition boxes. The rename tool will create a rename string like this: Fields in name mask + "." + Fields in extension mask. The reason why the two fields are separated is to prevent the accidental removal of file extensions, which would remove the association of files with a certain program.

Search & Replace    The string entered in the field 'Search for' is replaced by the string in 'Replace with'. The text in 'search for' is NOT case sensitive! Both fields support the placeholders (wildcards) * and ?. A * stands for any number of characters, a ? for exactly one character.

This function is applied AFTER the rename mask!
    New: You can now search+replace multiple strings in one step! The strings need to be separated by the vertical line (Alt+124).
    Example: Replace Umlauts+Accents:
    Search for: ä|ö|ü|é|è|ê|à  Replace with: ae|oe|ue|e|e|e|a

^    Respect upper-/lowercase. Can be used to replace uppercase characters with other charters than lowercase.
    Example: Replace Umlauts+Accents considering upper/lowercase:

Search for: ä|ö|ü|é|è|ê|à|Ä|Ö|Ü|É|È|Ê|À  Replace with: ae|oe|ue|e|e|e|a|AE|OE|UE|E|E|E|A

RegEx    Now supports regular expressions.

Subst.    Substitution: The entire file name will be replaced by the characters entered in the "Replace" field. If this option isn't checked, only the found expression will be replaced. You can work with subexpressions, see the sample in regular expressions.

Upper/lowercase    Converts the whole string to uppercase/lowercase/first letter uppercase,rest lowercase. This function is applied AFTER the rename mask and after search&replace. Use the [U], [L] and [n] placeholders to convert only certain parts of the name to upper/lowercase!

    Opens a context menu with the following options:
    Load names from file: Specify a text file from which the new names should be loaded
    Edit names: Save current target names to a text file, edit them, and paste back.

Configure editor: Choose a different editor to edit the files. Make sure that the editor saves as plain text!

Define counter [C]    Allows to define the counter for the [C] field(s).
Start at:    Number of the first file. The files are always numbered the same way as they are shown in the result list. You can sort the result list just like in the main Total Commander window. Additionally you can reorder individual items using drag&drop, or Shift+Cursor keys.

Step by:    The counter is increased/decreased by this value.
Digits:    Width of the counter field. If digits is >1, the rename tool will insert leading zeros to get a fixed width number field.

F2 Load/save settings
    Allows to load or save the settings of the multi-rename tool.
<Default>    Sets the default settings (no changes to the names)
Save settings
    Allows to save the current settings
Delete entry    Deletes the last selected entry from the list

Entry names    Loads settings saved earlier

<File list header>    Allows to sort by old names, extensions, sizes or time stamps
<File list>    Shows a list of all files being renamed. The modified names are shown in the New name column. All changes to the above fields are immediately shown in this column, but the files are not actually renamed until the Start! button is pressed. If the rename mask contains an error, the string <Error!> is shown.

Individual items can be moved up/down with drag&drop or Shift+Cursor keys. This is useful for changing the file order for the counter function.

(next step)    Loads the rename results for the next rename step. Useful if you want to apply multiple rename rules to the same set of files. Shortcut: F5.
Start!    Starts to rename files. There will be a warning message if there are name conflicts.
Undo    Tries to undo the rename operation in reverse order (last renamed file first). This also works AFTER closing the Multi-Rename-Tool! Just re-open it with any file(s).

Result list    Creates a protocol of the renamed files.
Close    Closes the dialog box without any further actions.

Here is a description of all available placeholders. IMPORTANT: Upper/lowercase is relevant!
[N]    old file name, WITHOUT extension
[N2-5]    Characters 2 to 5 from the old name (totals to 4 characters). Double byte characters (e.g. Chinese, Japanese) are counted as 1 character! The first letter is accessed with '1'.
[N2,5]    5 characters starting at character 2
[N2-]    All characters starting at character 2
[N-8,5]    5 characters starting at the 8-last character (counted from the end of the name)

[N-8-5]    Characters from the 8th-last to the 5th-last character
[N2--5]    Characters from the 2nd to the 5th-last character
[N-5-]    Characters from the 5th-last character to the end of the name
[2-5]    Characters 2-5 from the whole name and extension (other numbers as in [N] definition)
[P]    Paste name of the parent directory, e.g. when renaming c:\directory\file.txt -> pastes "directory".
    Also working: [P2-5], [P2,5], [P-8,5], [P-8-5] and [P2-], see description of [N] above.

[G]    Grandparent directory (usage: see [P]).
[E]    Extension
[E1-2]    Characters 1-2 from the extension (other numbers as in [N] definition)
[C]    Paste counter, as defined in Define counter field
[C10+5:3]    Paste counter, define counter settings directly. In this example, start at 10, step by 5, use 3 digits width.
    Partial definitions like [C10] or [C+5] or [C:3] are also accepted.
[Caa+1]    Paste counter, define counter settings directly. In this example, start at aa, step 1 letter, use 2 digits (defined by 'aa' width)

[d]    Paste date as defined in current country settings. / is replaced by a dash
[Y]    Paste year in 4 digit form
[y]    Paste year in 2 digit form
[M]    Paste month, always 2 digit
[D]    Paste day, always 2 digit
[t]    Paste time, as defined in current country settings. : is replaced by a dot.
[h]    Paste hours, always in 24 hour 2 digit format
[m]    Paste minutes, always in 2 digit format
[s]    Paste seconds, always in 2 digit format

[U]    All characters after this position in uppercase
[L]    All characters after this position in lowercase
[F]    First letter of each word uppercase after this position, all others lowercase
[n]    All characters after this position again as in original name (upper/lowercase unchanged)
[[]    Insert square bracket: open
[]]    Insert square bracket: close (cannot be combined with other commands inside the square bracket!)
[=pluginname.fieldname.unit]

Insert field named "fieldname" from content plugin named "pluginname". "unit" may be an optional unit (if supported by that field), or a field formatter like YMD for date fields. You can use the [=?] Plugin button to insert plugin fields.
[=pluginname.fieldname.unit:4-7]
    Same as above, but for partial strings (here: letters 4-7).

 

Appendix B. Total Commander regex support.

Regular expressions are a very powerful search tool. They allow to search for complex classes of words. Regular expressions are mainly meant for professionals, but can also be useful in the office for finding certain documents (see examples below).

Total Commander supports regular expressions in the following functions:
- Commands – Search (in file name and file contents)
- In Lister
- In the Multi-Rename tool
- In the selection dialog

Regular expressions consist of normal characters and special characters, so-called meta-characters. The following characters are meta-characters or initial parts of meta-characters:
.  \  (  )  [  ]  {  }  ^  $  +  *  ?    (only in character classes: – )

Normal characters:

test    finds the string "test" in the searched text. Note: This finds "test" ANYWHERE in a file name or on a line in text.

Escape sequences:

A backslash \ starts an Escape sequence. Examples for escape sequences:

\t    Tabstop
\xnn    Character with hexadecimal code nn. Example: \x20 is the space character. The character table charmap.exe (if installed) shows the character code of most special characters. You can use the Windows calculator in scientific mode to convert from decimal to hex.
\[    Left square bracket. Since the square brackets are meta-characters, they need to be written as \[ to search for them in the target string.
\\    Finds a backslash.
\.    Finds a dot ("." alone finds any character, see below).

Character classes

Characters in square brackets build a character class. It will find exacly one character from this class. A dash allows to define groups, e.g. [a-z]. A ^ at the beginning finds all characters except for those listed.
Examples:

[aeiou]    Finds exactly one of the listed vovels.
[^aeiou]    Finds everything except for a vovel.
M[ae][iy]er    Finds a Mr. Meier in all possible ways of writing: Mayer, Meyer, Maier, Meier. Very useful if you cannot remember the exact writing of a name.

Meta-characters

Here is a list of the most important meta-characters:

^    Line start
$    Line end
.    Any character
\w    a letter, digit or underscore _
\W    the opposite of \w
\d    a digit
\D    no digit
\s    a word separator (space, tab etc)
\S    no word separator
\b    finds a word boundary (combination of \s and \S)
\B    the opposite of \b

Iterators

Iterators are used for a repetition of the character or expression to the left of the iterator.
*    zero or more occurances
+    one or more occurances
{n}    exactly n occurances
{n,}    at least n occurances

{n,m}    at least n and max. m occurances

All these operators are "greedy", which means that they take as many characters as they can get. Putting a question mark ? after an operator makes it "non-greedy", i.e. it takes only as many characters as needed.
Example: "b+" applied to the target string "abbbbc" finds "bbbb", "b+?" finds just "b".

Alternatives

Alternatives are put in round braces, and are separated by a vertical dash.

Example: (John|James|Peter)  finds one of the names John, James or Peter.

Subexpressions for search+replace

Text parts in round braces are taken as subexpressions.
Example: To swap the title and interpret in the file name of an mp3 file, when they are separated by a dash (Title – Interpret.mp3), this can be solved like this:
Search for: (.*) – (.*)\.mp3
Replace by: $2 – $1.mp3
Here $1 means the text in the first brace, and $2 the text in the second brace.

Backreferences

\n    Finds subexpression n another time in the search result.

Example: (.+)\1+  finds e.g.  abab  (where the first ab is found by .+  and the second by \1+ )

Modifiers

Modifiers are used for changing behaviour of regular expressions.

(?i)    Ignore Upper-/lowercase. In Total Commander, this is the default for file names.
(?-i)    Case-sensitive matching.
(?g)    Switches on "greedy" mode (active by default)
(?-g)    Turns off "greedy" mode, so "+" means the same as "+?"

The other modificators are not relevant for Total Commander, because the program only supports searching within one line.

Total Commander uses the free Delphi library TRegExpr by Andrey V. Sorokin: http://www.regexpstudio.com/
Some of the above explanations are from the help file for this library.

● ● ●

Artem Russakovskii is a San Francisco programmer, blogger, and future millionaire (that last part is in the works). Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.

In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.



Share
  • http://omninoggin.com/ Thaya

    After learning Total Commander, my productivity increased 2 folds. I cannot live without Total Commander. Too bad I still cannot figure out how to recursively rename things in the totalcmd mass renaming tool.

  • http://beerpla.net Archon810

    Thaya, you can easily recursively rename files in all subdirs of a current dir by pressing ctrl-B and then selecting what you want. This won't work for dir names though, I'm not sure if that'd be possible at all right now.

  • Danny

    I've got several thousand directories that are people's names. What I'd like to do is rename all these directories so they are all last name first, then the rest of the name.

    Unfortunately the names aren't always the same length, but more often than not may include one or more middle initials as well, making it difficult for other renaming tools I've used to do the job.

    Let me know if your program can do that.

  • http://beerpla.net Artem Russakovskii

    Danny, post a few examples please. Also, what is the directory structure? Are all name directories in the same common directory?

  • Danny

    The directories are all just standard normal names, of different lengths, sometimes with one, maybe more middle initials:

    Tom Clancy
    J.R.R. Tolkien
    Ursula K. LeGuin
    George R. R. Martin

    What I want to do, is rename all these files so the last name is first, ala:

    Clancy, Tom
    Tolkien, J.R.R.
    LeGuin, Ursula K
    Martin, George R. R.

    • EagleOne

      Did you want to remane files or Folders? your post above says files…What I want to do, is rename all these files (or Folders) so the last name is first, ala:
      Clancy, Tom
      Tolkien, J.R.R.
      LeGuin, Ursula K
      Martin, George R. R.

  • Danny

    Each directory has various files inside, but those don't need renaming. And all the author named directories are located in a common single directory (in this case something like "Books")

  • http://beerpla.net Artem Russakovskii

    Sure, Danny. Here is what you should do. That's
    Regex:

    (.*?)(\S+)$

    Replace with:

    $2, $1

    Don't forget to check the Regex checkbox.

  • Tom

    Here is an example of my problem, ex: filenames are 12345delta.jpg , 12345charlie.jpg, 12345oscar.jpg — now say I only want to search for the first 5 digits which is 12345 and then once it brings me the results, I would like to copy them into the corresponding 12345 folder. Is this possible???? Thanks for your help!

  • Tom

    Another example which is more relevant would be the following. I would like to move filename 6061-26-706952-0000ex1.JPG into the folder 6061-26-706952-0000. Now to do this, I would need the program to only take the first 19 digits of each file, and then when i go to move them, I would need the program to match those 19 digits to each corresponding folder and finally place the .jpg files in their folders.

  • http://beerpla.net Artem Russakovskii

    Tom, sure, though it's not going to be fully automated. You wouldn't use the multi-rename tool for that. Instead, what you should do is:

    1. alt-f7 to search
    2. enter '12345*.jpg'
    3. when the results show up, press the "Feed to listbox" button – that will put all the found files into one virtual folder
    4. select them all and copy to a folder of your own

    OR

    1. Make a Perl script to do all this automatically :P

  • http://beerpla.net Artem Russakovskii

    Tom, Re: your second post.
    Your best bet would be a quick few lines of Perl code. Total Commander is a file manager, not a programming language :) Unfortunately something that could be a quick hack (i.e. using mass rename tool to rename a 100-foo.jpg as 100/100-foo.jpg) didn't work, as Total Commander didn't understand I wanted to create a path.

  • Tom

    Reply to Perk: I would have no idea where to begin with that being I dont have the background in it lol. Could you possibly post the code that might get me started with this problem? : Another example which is more relevant would be the following. I would like to move filename 6061-26-706952-0000ex1.JPG into the folder 6061-26-706952-0000. Now to do this, I would need the program to only take the first 19 digits of each file, and then when i go to move them, I would need the program to match those 19 digits to each corresponding folder and finally place the .jpg files in their folders

  • http://beerpla.net Artem Russakovskii

    Here's something I quickly threw together. It does exactly what you want. You will need Perl (Windows or Linux, doesn't matter), and the libraries listed at the top (type in cpan, then install LIBNAME).

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    #!/usr/bin/perl -w
    # This script will move files in a directory to directories named by the first 19 characters of each file.
    # Author: Artem Russakovskii.
     
    use File::Find::Rule;
    use Data::Dumper;
    use File::Copy;
     
    # config - change this
    my $start_dir = ".";
    my $file_pattern = qr/\.jpg$/i;
     
    # rest
    foreach my $file (File::Find::Rule->file()->name($file_pattern)->in($start_dir)){
      if($file =~ /^(.{19})/){
        my $dir_wanted = $1 ;
        print "Found file $file to go to $dir_wanted.\n";
        mkdir($dir_wanted);
        move ($file, $dir_wanted) or warn "Couldn't move file $file\n";
      }
    }
  • Ahab

    Hi,

    How can I do this :

    Files with different names are in one directory and I would like to rename them to have more or less random names (i.e.using "time" for name as result is OK – but if it can be even more random the better) and I want them to be copied to another directory at the same time where they would land renamed while the original files remain untouched.

  • http://beerpla.net Artem Russakovskii

    Ahab, you probably don't need Total Commander for this. First, copy the files into a separate folder, so that the originals remain untouched. Then use a quick Perl script, or whatever your language of choice is, to alter the file names in place. I'm sorry but I don't have time to provide a code snippet.

  • P.

    Hi, guys .. this "tutorial" helps me much, but i have still one problem. I have files like 1,10,11,12,2,3,… and target is add a leading zeroes (for better sorting and viewing). I still dont know how to to this with TC :(

  • http://beerpla.net Artem Russakovskii

    P., I currently can't think of a fully automated way to do this with TC. You are probably better off with a Perl script if you're doing this more than once.

    If it's a one-time deal, then you can do a few manual replaces like this (let's assume you want the length of your names to be 4 digits long):

    Regex:

    ^(\d{1})$

    Replace with:

    000$1

    Regex:

    ^(\d{2})$

    Replace with:

    00$1

    Regex:

    ^(\d{3})$

    Replace with:

    0$1

    You can use the same approach if you want to pad with more 0s.

  • proslaviy

    Hi, how I can send PM?

  • http://beerpla.net Artem Russakovskii

    proslaviy, just use the form on the About Me page.

  • CKJ

    Great tutorial.

    Just to respond to another poster:

    > Archon810No Wrote:
    > Thaya, you can easily recursively rename files in all
    > subdirs of a current dir by pressing ctrl-B and then
    > selecting what you want. This won't work for dir names
    > though, I'm not sure if that'd be possible at all right
    > now.

    1: Go to the root directory (containing all the sub-directories you want to rename) and press Alt-F7. The "Find Files" dialog will open.
    3: In the "General" tab, make sure the "Search for" box is empty (all directories will be matched) and then go to the "Plugins" tab.
    2: Check the "Search in Plugins" box and select the following values (name[value]): Plugin[tc], Property[directory], OP[=], Value[Yes].
    3: Press the "Start Search" button.
    4: When the search has completed, select "Feed to listbox" button at the bottom right.
    5: Select all these (Ctrl-NUM+) and then press Ctrl-M to do the multi-rename as described in this tutorial.

  • http://beerpla.net Artem Russakovskii

    CKJ, ah, I didn't think of that one, though I most certainly use the listbox functionality on almost a daily basis. I still think Total Cmd should provide better options for doing mass directory renaming but you're right, that will work.

    Thanks.

  • CKJ

    > CKJ, ah, I didn't think of that one, though I most certainly
    > use the listbox functionality on almost a daily basis. I still
    > think Total Cmd should provide better options for doing mass
    > directory renaming but you're right, that will work.

    I agree, although until a new version adds these better options, the admittedly somewhat convoluted method I presented is still preferably to having to dig through each of the sub-directories one by one, possibly with multiple levels of depth.

    I need to rename directories reasonably frequently so I have it down to just remembering the key strokes:

    1: Alt-F7 – to open "Find Files" window.
    2: Delete – the "Search for" box will have focus so this clears any pattern in there, allowing matching all directories.
    3: Ctrl-Tab x 2 – to get to the Plugins tab.
    4: Tab, then Spacebar – to enable the "Search in plugins".
    5: Enter – to do the search
    6: Tab, tab, d, d – only do this step if the settings on the Plugins page haven't been set. (Sets Property to 'directory' and uses defaults for the other values. 'tc' is the first item in my Plugin list so I don't need to change that.)
    7: Alt-L to feed to listbox

    This could be seen as complicated but I'm a keyboard junkie (what user of Total Commander isn't right?) and keeping it keyboard controlled makes it a quicker process than otherwise. It can probably be automated in some way (a desktop macro tool for example), I haven't looked at doing that.

    Maybe this is helpful to someone out there, maybe not. Just thought I'd share. :)

    P.S. I apologize for the lazy editing in my last post. It was late and I only double-checked the content, not the list numbers.

  • http://beerpla.net Artem Russakovskii

    You become a keyboard junkie with Total commander – that's for sure. Every operation is so fast, people's jaws drop when they watch me. Some of my personal favorites since we're talking about it:

    – I switched the Quicksearch to Alt, so I just hold Alt and start typing away, Enter, alt type, enter, etc. Navigation is insanely fast that way.

    – ctrl-B for listing files in all subdirs

    – ctrl-T for tabs and ctrl-TAB for navigating around them

    – ctrl-D for quick favorite list

    – alt-f5, alt-f9 for packing/unpacking archives

    – entering archives with ctrl-pgdown (even if they don't have an archive extension)

    – alt-left and alt-right for dir history

    etc.

    Mice are awkward.

  • CKJ

    I noticed an error in my last post: item 6 should be above item 5. This is why I shouldn't post after having been up all night working!

    > Every operation is so fast, people's jaws drop when they watch me.

    I've had similar reactions. I like the interest the program sometimes generates, such that people end up making the switch themselves. That's a nice thing to see.

    If I'm honest I find it amusing to watch anybody attempting serious file organization using several Explorer windows. Like so many others I've been spoiled by commander applications and I couldn't live without them. I use TC on Windows exclusively (IMHO no other can touch it) and two others on my Linux box (one GUI, one CLI-based).

    > Some of my personal favorites since we're talking about it:
    > …

    I use all of those frequently, along with my particular favorites: alt-f1/alt-f2 to select the drive for the left/right panes, respectively.

    These are favorites because of their humble yet significant contributions to my efficiency.

    Some others I use frequently are:

    – alt-down for the history.

    – shift-f6 to rename a file/directory in place.

    – shift-f6 on the ".." item to enter a path (useful for entering a network resource path directly).

    – ctrl-shift-f5 to create a shortcut.

    – shift-f5 to create a copy of a file/directory with a different name in the same directory (i.e. not in the second pane).

    Mice definitely are less efficient for TC when pitted against an experienced keyboard user.

    The only disappointment I have with Total Commander is that there isn't a Linux port :)

  • http://beerpla.net Artem Russakovskii

    Heh heh, I can see a power user from your email. Almost no one knows about the "+" gmail trick. ;)

  • http://dadecoders.blogspot.com dadecoders
  • http://netreview.de Daniel

    Thx for this great tutorial. Keep it up.

    Greets

  • http://www.mluedeke.de Micha

    Thanks for the really great tutorial from my side, too!

    I have one question left though and I am not sure whether I could've answered it myself already by the written comments.

    I have some files

    01_bla.rtf
    02_bli.rtf
    03_blupp.rtf
    04_blau.rtf
    05_blumm.rtf
    and want to rename just one or two and get the others in order again.

    01_blau.rtf
    01_bla.rtf (should then become 02_bla.rtf)
    02_bli.rtf (should become 03_bli.rtf…)
    03_blupp.rtf
    05_blumm.rtf
    It seems like a simple thing but I just don't get it yet… ;)
    Thanks for your help beforehand!
    Micha

  • http://beerpla.net Artem Russakovskii

    @Micha
    I'm afraid something like this needs a bit of custom logic, so it has to be a script.

    However, depending on if this is OK with you or not, you can first try to use this regex to eliminate all digits from the beginning: ^d+ and then separately attach a counter using the [C] modifier in the name.

  • http://www.hatemalo.de Micha

    Oh, too bad. But thanks for the fast response anyway.
    Micha

  • t0ny

    Wow, great post.
    Please let me know if it's posssible to do the following with TC.

    I have the folder "abc" and inside this folder I have files: 01.jpg, 01_xl.jpg, 01_l.jpg, 02.jpg, 02_xl.jpg, 03.jpg

    Is there any chance to renema them using the folder name?

    So the result should be:
    01.jpg
    01_abc_xl.jpg
    01_abc_l.jpg
    02_abc.jpg
    02_abc_xl.jpg
    03_abc.jpg

    So I'd need to find "_" and place "_[PARENTFOLDERNAME]" after that?

    Thanks
    t0ny

  • t0ny

    I think I've got it!

    Rename mask: [N][P]

    Search for: (.*)_(.*)_(.*)_(.*)\.jpg
    Replace with: $1_$3_$4_$2.jpg

    Coool! Thanks!

    Is there any chance to process Multi Rename Tool in subfolders?

    So for example: I've got folder "todo" and 50 folders inside with files that needs renaming. Can I do it at once or I have to go inside to every of those 50 folders?

    Thanks
    t0ny

  • Olivier

    Hello
    I also love TT and can't work without it !
    But a great lack in Multi Rename tool is the ability to simply add leading or trailing characters to the file name

    Example

    rename
    1.txt
    12.txt
    2.txt

    to
    001.txt
    012.txt
    002.txt

    • http://beerpla.net Artem Russakovskii

      Yeah, I don't think you can pad with 0s like this in TC (what's TT? :P) in one go, but you can split the task up in a couple and do them one after the other.
      For example,
      search for ^(\d\.txt), rename to 00$1
      Then
      search for ^(\d{2}\.txt), rename to 0$1

      • Jan

        Hi all,
        I can help.
        I have solved a problem with google Picasa application.
        The result of renaming and reordering photos from this application looks like:
        myHoliday.jpg
        myHoliday-1.jpg
        myHoliday-10.jpg
        myHoliday-11.jpg
        myHoliday-12.jpg
        myHoliday-13.jpg
        myHoliday-14.jpg
        myHoliday-15.jpg
        myHoliday-16.jpg
        myHoliday-17.jpg
        myHoliday-18.jpg
        myHoliday-19.jpg
        myHoliday-2.jpg
        myHoliday-20.jpg
        myHoliday-21.jpg
        myHoliday-3.jpg
        myHoliday-4.jpg
        myHoliday-5.jpg
        myHoliday-6.jpg
        myHoliday-7.jpg
        myHoliday-8.jpg
        myHoliday-9.jpgand so on.
        I need
        myHoliday-000000.jpg
        myHoliday-000001.jpg
        myHoliday-000002.jpg
        myHoliday-000003.jpg
        myHoliday-000004.jpg
        myHoliday-000005.jpg
        myHoliday-000006.jpg
        myHoliday-000007.jpg
        myHoliday-000008.jpg
        myHoliday-000009.jpg
        myHoliday-000010.jpg
        myHoliday-000011.jpg
        myHoliday-000012.jpg
        myHoliday-000013.jpg
        myHoliday-000014.jpg
        myHoliday-000015.jpg
        myHoliday-000016.jpg
        myHoliday-000017.jpg
        myHoliday-000018.jpg
        myHoliday-000019.jpg
        myHoliday-000020.jpg
        myHoliday-000021.jpg
        In multirename tool:
        name: [N]0
        ext: [E]
        check box regex
        find: ([a-zA-Z]+)-?((\d\d\d\d\d\d)0|(\d\d\d\d\d)(0)|(\d\d\d\d)(0)|(\d\d\d)(0)|(\d\d)(0)|(\d)(0)|(0))
        replace: $1-$3$5$4$7$7$6$9$9$9$8$11$11$11$11$10$13$13$13$13$13$12$14$14$14$14$14$14

        If you think I am a very very clever man, I have to agree :-)
        Cheers
        Jan

        • Miguel

          AT LAST!
          This was the solution to my problem (September 22)
          Thank you and Artem as well!

        • http://beerpla.net Artem Russakovskii

          Excellent, I've actually had to do this a few times and used a bunch of runs through TC. The only thing I'd do if this indeed works is replace multiple \d with \d{N} where N is the number of repetitions. For example \d{6}.

          Thanks, clever Jan.

  • Hannes Vandevelde

    Hello i have small problem:
    i have 30+ folders with similar files in them.
    i want to rename all the files in the folders to [P]-[C] (counter resetting in each folder)

    is there a short way to do this?

    • http://beerpla.net Artem Russakovskii

      I don't think so, Hannes. You may need to write a script to do this.

    • Carlos

      You can do a search (Alt + F7) to get all the files, click "Feed to listbox", select all (Ctrl + A) and rename (Ctrl + M).

      You can use something similar (search + feed to listbox) to, for example, selectively copy multiple files in different directories to a new one.

      • http://beerpla.net Artem Russakovskii

        That won't work because this method won't reset the counter in each folder.

  • Wilson

    Thanks for all the useful posts. However, I still can't figure out how to use TC to solve my problem in doing some re-numbering of the filenames where TC adds or subtracts a fixed number from the original filename:

    3230 to change to 58 (minus 3172)
    3232 to change to 60 (minus 3172)
    3235 to change to 63

    File numbering may jump so output file numbers must jump accordingly too.

    Any suggestions would be greatly appreciated.

    • http://beerpla.net Artem Russakovskii

      Unfortunately, I don't think that's possible with TC or regular expressions because it involves math. I may be wrong though.

  • Miguel

    I've found that the regular expression for renaming files with leading zeros (from name1.txt to name_01.txt, etc) would be

    /(file)([0-9])/\1_0\2/

    but I couldn't execute it in TC. Could you "translate" it? Great site. Thanks.

    • http://beerpla.net Artem Russakovskii

      What you found is probably the way it's used in a Perl or PHP script, or something.

      To use it in TC, just tick the RegEx box, then input:

      Search for: (file)([0-9])
      Replace with: $1_0$2

      • Miguel

        Thanks. But does nothing…

        • http://beerpla.net Artem Russakovskii

          You're supposed to replace "file" with your own file name pattern – I'm guess that's what you meant by "does nothing".

          Otherwise, just replace "file" with [a-zA-Z], including the square brackets, and that should match any base name with those characters.

  • Miguel

    I've tried these, which all of them do nothing:

    Search for: [a-zA-Z]([0-9])
    Search for: ([a-zA-Z])([0-9])
    Search for: [a-zA-Z][0-9]

    ALWAYS WITH

    Replace with: $1_0$2 AND RegEx checked

    Something i'm doing wrong…?

    • http://beerpla.net Artem Russakovskii

      The 2nd option should work just fine: http://i.imgur.com/o3ndC.png

      If something doesn't work, I suggest you spend some time and learn the basics of regular expressions – things will make sense then, I promise.

  • Teris

    Thanks for all the useful posts. However there is something I cant do.
    I want to add an Underscore before a capital letter, for example

    2010HelloFirst
    2010YesOk

    to

    2010_Hello_First
    2010_Yes_Ok

    any help appreciated!

    • http://beerpla.net Artem Russakovskii

      All of these questions are simply turning into regex help. I will help this time but I am getting a bit too busy to provide support to everyone.

      Please learn regex.

      In your case, it's very simple:
      Search for: ([A-Z])
      Replace with: _$1
      Check: RegEx and Respect Case (^) checkboxes

  • Teris

    thank you Artem,
    where can I read about how Regex works?

  • John

    Artem, you've got some great information here. I just discovered Total Commander and I think it's going to make my life much easier now. I have a quick question for you if you don't mind. I've got several thousands of songs in my MP3 collection. Many of them have a number in front of the filename. For example.
    01 Knowing What I Know Now.mp3
    02 Ice Cream.mp3
    05 Ricochet in Time.mp3
    The only problem is that there are variations in the numbering. So some of the others are like thus:
    01 – Cry Like an Angel.mp3
    02-Love Came Down At Christmas.mp3
    03_Mystery.mp3
    04 20 Balloons.mp3
    I looked on the Regex tutorial website you pointed out, but I cannot figure out how to rename the files in the manner I'm looking for. If I use the following regexp: ^d{2}
    It does not produce the results I'm looking for because of the variations in the numbers in the front of the filename.
    Is there some type of regexp that can disregard the first two digits in the filename, if the 3rd is a space, or a dash or a underscore, then move on to the next character until you run into an actual letter or another number?

    Basically, I want the final result to look like:

    Cry Like an Angel.mp3
    Love Came Down At Christmas.mp3
    Mystery.mp3
    20 Balloons.mp3

    I'm completely stumped. Any help would be appreciated.

    • http://beerpla.net Artem Russakovskii

      John, I actually had to do exactly the same and wrote up a regex for it. I'm having some remodeling done right now, so my desktop is off, but once I turn it back on, I'll post it up.
      Btw, you don't want to delete all numbers – usually just the first one, because that number could be part of the song's name.

      • John

        Artem,

        Just curious to know if you've had a chance to power on your PC again. I'm really looking forward to the reg exp you wrote.

        • http://beerpla.net Artem Russakovskii

          John, unfortunately, not yet. It's still sitting in a pile of construction dust :)

    • http://beerpla.net Artem Russakovskii

      John, I was finally able to get the regex you were looking for:

      Search for: ^\d+\s*[\-\._]*\s*
      Replace with: <Clear>
      RegEx: checked
      • John

        Oh fantastic. I'll give it a try this week and report back. Thanks Artem.

      • John

        Artem, just a little feedback. It works great except for in one instance, I had a song title:
        1999.mp3

        The regexp code you gave me wiped out the entire name. Luckily I caught it in the preview before making the change. Thanks for providing the code.

  • Goran

    Artem, realy great tips you have here. I've been looking for this on official TCM site for some time. The trick with Parent and Grandparent saved me quite time.

    Pitty Counter reseting doesn't work…

    Cheers!

  • John

    Hey Artem, just wanted stop by and wish you a happy new year. Thanks for all your help! Cheers.

    • http://beerpla.net Artem Russakovskii

      Hey, thanks John, very nice of you! Happy New Year!

  • jan

    One important note. The power of regular expressions is small comparing to universal (normal) programing language. So no surprise that sometimes it is not possible tu use it. One not useful example is renaming file if the name is a number and prime. It is not possible and it is not difficult to prove it.

  • Eugene

    What if I have a list of files that is numbered

    fliename0001
    filename0056
    filename0999
    filename1100

    And I want the numbers in each filename to decrease by 1?
    Thanks

    • http://beerpla.net Artem Russakovskii

      Afraid you can't do that without a script.

    • Nick

      Or:
      1. Export the file names to an Excel Spreadsheet
      2. Separate text from numbers in different cells
      3. Decrease the numbers as u like using a @formula
      4. Concatenate text+numbers
      5. Import the result cells to multi rename txt file
      6. Check the resulted (Old vs. New)names are as desired in the multi rename screen and click "Start". U always have the security option of one (1) backup, in case something went wrong.

  • Tom

    Hi Artem,

    I have a pretty easy one for you (but I can't figure it out).

    I have a set of directories I use as a template/container for job files. (about 130 directories) they are empty. and have varying lengths: e.g.

    Blank month/translation/RU/word/clean
    Blank month/translation/EN/send

    I want to have several sets

    Blank month/RED translation/RU/word/RED clean
    Blank month/BLUE translation/RU/word/BLU clean
    Blank month/GRN translation/RU/word/GRN clean

    Blank month/RED translation/EN/RED send
    Blank month/BLU translation/EN/BLU send
    Blank month/GRN translation/EN/GRN send

    Possible? Pomogi chainiku!

    Best,

    Tom

    • Tom

      I should say that I am perhaps not as incompetent as I presented myself. I have used regex in the past, and it is more or less clear how to change file names, but it is not clear how to change empty directories.

      Also, I can modify my task to make it somewhat easier – I can rename all directories….

      BLU Blank month/BLU translation/BLU RU/BLU word/BLU clean
      GRN Blank month/GRN translation/GRN RU/GRN word/GRN clean

      • Tom

        I guess Total Commander can't handle this.

        I'll need to look for a more powerful tool.

  • Sreve G

    I am trying to find the pattern in a file name of "digit digit" (ie User manual v2 9 878 2011.pdf) and renaming it to User Manual v2.9.878 2011.pdf.
    I am finding all these files using the
    ([0-9]) ([0-9]) and expecting to rename them using the > $1.$2 function, which is fine for the first pattern matched in my example but not for subsequent matches in the same name.
    I can run it multiple times but guessing there is a better way:>
    Brilliant stuff here, and thanks in advance
    Steve

    • http://beerpla.net Artem Russakovskii

      In your case, indeed such a substitution would need to be applied multiple times, because matches in that regex can't cross characters.

      There is a way to solve it using advanced regex with the use of positive lookbehinds and lookaheads, and I verified it works, but TC doesn't seem to support them.

      This is the right way to do this if it did.

      Search for:

      (?<=\d) (?=\d)

      Replace with:

      .

      More info about positive lookaheads and lookbehinds: http://www.regular-expressions.info/lookaround.html

  • Ewa

    I've been trying to read about the renaming, got a headeach, and still can't get it to work. Could you explain for people who, like me, do not speak the computer language? I have no idea what is "place holder".

    I would like to change:

    01 Place 01-03.ext
    02 Place 02-03.ext
    etc.

    to:

    03-01.ext
    03-02.ext
    etc.

    How do I go about it?

    Ewa

  • Steve

    Hi Artem – Can Total Commander help when you've given a huge 35mm slide collection to a scanning company and instead of scanning the slide trays, from oldest to newest, one-at-a-time, as requested of them, the scanner mixed the order. So now the simplistic ‘file date’-centric SD card slide show generators built into most monitors shows the slides out of sequence. And the only faint hope is that within the slide tray directories the JPG files there as always named w/a leading number that's is in the time-correct order. So is Total Commander capable of proceeding in the correct directory order and changing some minor field (ie: to 100% avoid effecting image quality) of the JPG header/meta-data info & re-saving each file so that the new file dates finally ascend in the same manner as the numerical file name ?

  • Nick

    Wondering if it's possible to select files starting with a specific character.
    e.g. "A" or "B"
    In what i'm trying to solve i need to copy a long list of files to folders named A,B…Z according to the letter the file has as its 1st character.
    Till now i use the keyboard to select the files, but since i use that repeatedly, i'm wondering if its possible of a more automated way to do that.

  • Revolver Revolved

    it works but with _$0

  • sadistic_son

    Hi. Can somebody please help me to build regexp to remove everything before last underscore? For example I got many files with name format like: Untitled000XX_00X_00XX_0YY.jpg where X and Y are different numbers and where there are different ammounts of underscores. I need this file to be renamed as 0YY.jpg – so all what is before the LAST underscore has to be erased. Any ideas? Thank you.

  • d.orin

    i know this answer comes 5 years later, but it was also one of my problems and it was answered (partially) in a reply above:
    – you need to have some similarity in your files
    – you can not reset the counter in the next directory.
    – you can search for something in your "to do" folder, some generig search that would return all the files you need to rename.
    – once you do that, feed to listbox
    – select all
    – Ctrl+M
    – enjoy

    For example, I had a structure like:
    C:PicturesPersonNamePictureGenericName.jpg
    I wanted to have the structure:
    C:PicturesPersonNamePersonName – PictureGenericName.jpg
    (all pictures names renamed to include PersonName (parent folder name))
    I just searched in C:Pictures all *.jpg files, fed them to the listbox, and then renamed using [P] – [N]