Multi-renaming many files with different masks

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
Minamoto Kobayashi
Junior Member
Junior Member
Posts: 2
Joined: 2016-03-13, 03:04 UTC

Multi-renaming many files with different masks

Post by *Minamoto Kobayashi »

Hello from Italy :)
I'm planning to buy this wonderful program, but the only purpose will
be to do a multi-renaming of a large amount of directories every month.
Please remind that every dir has a different renaming procedure.

For example:

the first operation for all the dirs: "capitalize first letter words"

then:

" V" - must be replaced with " v"
" build " - must be replaced with "."
" (full)" - must be deleted
" [Subscribed]" - must be deleted

.. and so on.
There is the possibility to do all the operations with only one click?
Thanks in advance for the help!
User avatar
ts4242
Power Member
Power Member
Posts: 2081
Joined: 2004-02-02, 20:08 UTC
Contact:

Post by *ts4242 »

Yes you can replace more than one string in one step
TC help wrote: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
To capitalize first letter, select "First letter uppercase" from Upper/lowercase dropdown list
Minamoto Kobayashi
Junior Member
Junior Member
Posts: 2
Joined: 2016-03-13, 03:04 UTC

Post by *Minamoto Kobayashi »

Thanks for the fast reply!
But must I write the entire strings inside the two "Search for" and "Replace with" small windows?
How many long can be the entire string? I have more than 40 replaces to do!
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

If you need to do mass-renames in different folders with different complex schemes every month, perhaps you need some another tool for such task because you can't schedule renames with TC and you can't run multiple rename tasks at once, you only can save presets for every folder and run then one by one.
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Hello and welcome to the community, Minamoto Kobayashi


For such renaming task I would utilize a script.
(DOS, PowerShell, AHK, VBS)


my.VBS
- For each line in temp-file-list (due to TCs %L parameter)
-- newname = replace(oldname, " V", " v")
-- newname = replace(newname, " build ", " .")
-- and so on...
---- Rename oldname newname
- Next

- - -

Use TotalCommander to provide the selected files to that script:
my.VBS "%L"


Open any button bar button and press F1 key to read more about %L parameter and others.

To select from all sub folders, utilize TCs Branch View first.


- - -

You can add such script to the button bar
or create a user command to add a keyboard shortcut.

http://ghisler.ch/board/viewtopic.php?p=291895#291895


- - -



If you need more help, just ask

 
User avatar
nsp
Power Member
Power Member
Posts: 1951
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Post by *nsp »

MVV wrote:If you need to do mass-renames in different folders with different complex schemes every month, perhaps you need some another tool for such task because you can't schedule renames with TC and you can't run multiple rename tasks at once, you only can save presets for every folder and run then one by one.
You can can use TC for it but to do all in one click could be hard to achieve specially if your source folder names correspond to different schemes.
First step is to use all TC fields to gather the information you need and do some basic transformation and then use renaming to delete, replace, re-order...
If you know well Regexp you could do a lot the best could be to save the preset unfinished and then edit the entire expression from the ini file.

Another tool like Bulk Rename Utility and the associated command line Bulk Rename Command could also be a good option.
User avatar
brian
Junior Member
Junior Member
Posts: 67
Joined: 2003-09-25, 01:14 UTC
Contact:

Post by *brian »

Stefan2 wrote:Hello and welcome to the community, Minamoto Kobayashi
For such renaming task I would utilize a script.
(DOS, PowerShell, AHK, VBS)
If you need more help, just ask

 
How do I use scripts, (or WinCmd own rename tool), to replace strings? and since when is there no restriction on strings longer than 256 characters? Or is there still one?

I don't have any script experience, just some experience with COBOL, 16 years ago...... :)

My example is below.
| S01E| - 01|.1| S02E|.S02E| - 02x|.2x|.S03E| - 03x| - 03x| S03E| S04E|.S04E| - 4x| - 04x| S05E|.S05E| - 5x| - 05x| S06E|.S06E| - 6x| - 06x| S07E|.S07E| - 7x| - 07x| S08E|.S08E| - 8x| - 08x| S09E|.S09E| - 9x| - 09x| S10E|.S10E| - 10x| - 10x| S11E|.S11E| - 11x| - 11x| S12E|.S12E| - 12x| - 12x| S13E|.S13E| - 13x| - 13x|.720p|english.|.edit.|Addic7ed.com|C.|.updated|.webrip|.HDTV| x264|[ettv]|[eztv]|.WEB-DL|-LOL|.xvid|.x264|-[rarbg.to]|.ac3| (2016)|.2016
|.1x|.1x|.1x|.2x|.2x|.2x|.2x|.3x|.3x|.3x|.3x|.4x|.4x|.4x|.4x|.5x|.5x|.5x| 5x|.6x|.6x|.6x| 6x|.7x|.7x|.7x| 7x|.8x|.8x|.8x|.8x|.9x|.9x|.9x|.9x|.10x|.10x|.10x|.10x|.11x|.11x|.11x|.11x|.12x|.12x|.12x|.12x|.13x|.13x|.13x| 13x|
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

brian,

TCs parameter "%L" (use quotes) provides path to temp file with all selected file names.
(right click an button, chose "Change...", press F1 key and read the help for more)


Use "%L" as parameter for your script "MyScript.vbs":
CMD    = "path to\MyScript.vbs"
PARAM= "%L"

to process each selected file.





"MyScript.vbs" contains for example:

Code: Select all

'// ===========================================================
'// VBScript for Total Commander, by Stefan
'// _ForEachSelFileDo.vbs, Version 16.0228, 2016-02-28
'// Forum: http://ghisler.ch/board/viewtopic.php?p=323561#323561

'// Purpose:
'//     Example:
'//
'// TC Button:
'//         CMD:   "D:\rive\path\to this\MyScript.vbs"
'//         PARAM: "%L"
'// USAGE: Scroll down to "UserWorkHere" and add your code.
'//        Select your files, execute this script... done.
'// ===========================================================
On Error Resume Next 
Set FSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8 

If (Wscript.arguments.count < 1) Then 
    MsgBox "Please use from TC with parameter like '%L'",,"VBScript - ERROR"
    WScript.Quit
Else
    sTCtempList = Wscript.arguments.Item(0) ' The TC temp file due the "%L" 
End If


If  FSO.FileExists(sTCtempList) Then
    Set oTextStream = FSO.OpenTextFile(sTCtempList,ForReading)
    sFileContent = oTextStream.ReadAll
    oTextStream.Close
    aLineArray = split(sFileContent,vbCRLF) 
    '// =================== For each line in TCs temp list, Do your work:
    For i=0 To  UBound(aLineArray) -1
        Set oItem   = FSO.GetFile(aLineArray(i))   '//Ex: "X:\Work\Orders\File.txt"
        sPath       = oItem.ParentFolder            '//Ex: "X:\Work\Orders" 
        sPath       = sPath & "\"                   '//Ex: "X:\Work\Orders\" 
        sOldName    = FSO.GetFileName(oItem)        '//Ex: "File.txt"
        sBase       = FSO.GetBaseName(oItem)        '//Ex: "File"
        sExte       = FSO.GetExtensionName(oItem)   '//Ex: "txt" 


      '// ################################################################## UserWorkHere:
      '// DO YOUR WORK HERE (For each line in TCs temp list): 

        sNewName = Replace(sOldName, "a","X")
        sNewName = Replace(sNewName, "e","Y")
        sNewName = Replace(sNewName, "o","A")
        'D:\ForEachSelFileDo.vbs
        'D:\ForEXchSYlFilYDA.vbs

        MsgBox sPath & sOldName & vbLF & sPath & sNewName
        If NOT (FSO.FileExists(sPath & sNewName)) Then
            '//Command disabled by comment sign ' :
            'FSO.MoveFile sPath & sOldName, sPath & sNewName
        Else
        End If

      '// DO YOUR WORK ABOVE.
      '// ################################################################## 

    Next
Else
    MsgBox "Input file 'sTCtempList' (%L)  not found OR no selection done before.",,"TCs-VBScript - ERROR"
    WScript.Quit
End If 


All you need to do is:

- save the code as "MyScript.vbs"

- modify the "DO YOUR WORK HERE" part (ask if you need help)

- create a TC Button:
CMD: "D:\rive\path\to this\MyScript.vbs"
PARAM: "%L"


- select the files (utilize Branch View first to process sub folders)

- press the button to execute the script






There are more examples >> http://ghisler.ch/board/viewtopic.php?p=305571#305571


I need to add this topic to my FAQs >> http://ghisler.ch/board/viewtopic.php?p=287481#287481




 
User avatar
Dalai
Power Member
Power Member
Posts: 10032
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

I would seriously consider RegEx in such a case. Yes, it's work to build up a working and reliable solution, but IMO it's worth it.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
brian
Junior Member
Junior Member
Posts: 67
Joined: 2003-09-25, 01:14 UTC
Contact:

II

Post by *brian »

thank you both, S and D.
I don't know if i will have the stomach for it (mainly cos the string length seems expanded), but at least the option is there.
Post Reply