36

Mass Renaming Directories And Files Using Total Commander


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

36 Responses to “Mass Renaming Directories And Files Using Total Commander”

    36 Comments:
  1. Thaya says:

    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.

  2. Archon810 says:

    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.

  3. Danny says:

    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.

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

  5. Danny says:

    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.

  6. Danny says:

    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")

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

    (.*?)(\S+)$

    Replace with:

    $2, $1

    Don't forget to check the Regex checkbox.

  8. Tom says:

    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!

  9. Tom says:

    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.

  10. 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

  11. 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.

  12. Tom says:

    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

  13. 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";
      }
    }
  14. Ahab says:

    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.

  15. 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.

  16. P. says:

    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 :(

  17. 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.

  18. proslaviy says:

    Hi, how I can send PM?

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

  20. CKJ says:

    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.

  21. 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.

  22. CKJ says:

    > 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.

  23. 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.

  24. CKJ says:

    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 :)

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

  26. Daniel says:

    Thx for this great tutorial. Keep it up.

    Greets

  27. Micha says:

    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

  28. @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.

  29. Micha says:

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

  30. t0ny says:

    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

  31. t0ny says:

    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

  32. Olivier says:

    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

  33. @Olivier

    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

  34. Hannes Vandevelde says:

    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?

Leave a Reply

Connect with Facebook