Multirename tool: computed range instead of fixed range
Moderators: Hacker, petermad, Stefan2, white
-
- Junior Member
- Posts: 37
- Joined: 2011-04-01, 21:11 UTC
Multirename tool: computed range instead of fixed range
Hello all,
there is a way to specify a computed value instead of a fixed number, where a character position is required?
Example:
Name-123_abcdef.txt
Surname-65345_asdad.txt
Dude-567_qqqq.txt
I want to select the "Name", "Surname", "Dude" part of file names, which are clearly not selectable with fixed position values.
There should be a function like the VB6 "InStr" returning the position of a substring of the filename, so we can write something like N[1,InStr(1,Filename,"-")-1] to get everthing before "-" char.
there is a way to specify a computed value instead of a fixed number, where a character position is required?
Example:
Name-123_abcdef.txt
Surname-65345_asdad.txt
Dude-567_qqqq.txt
I want to select the "Name", "Surname", "Dude" part of file names, which are clearly not selectable with fixed position values.
There should be a function like the VB6 "InStr" returning the position of a substring of the filename, so we can write something like N[1,InStr(1,Filename,"-")-1] to get everthing before "-" char.
There is a regex support for search and replace so you can do whatever you want with it.
E.g. I'll replace Name part with file size and abcdef part with NTFS file index (regardless of part lengths):
Result:
E.g. I'll replace Name part with file size and abcdef part with NTFS file index (regardless of part lengths):
Code: Select all
Filename mask: [N]$[=tc.size.bytes]$[=ntlinks.Object Index]
Search for: ([^-]+)-(.*)_(.*)\$(.*)\$(.*)
Replace with: $4-$2_$5
[E]: yes
RegEx: yes
Code: Select all
20-123_000C000000107E1E.txt
33-65345_00440000000BA61A.txt
10-567_0002000000107E22.txt
MRT: all everything before after dash hyphen minus
FROM:
Name-123_abcdef.txt
Surname-65345_asdad.txt
Dude-567_qqqq.txt
TO:
Name-XXX123_abcdef.txt
Surname-XXX65345_asdad.txt
Dude-XXX567_qqqq.txt
USE:
Name: [N]
Exte: [E]
Search: (.+?-)
Replace: $1XXX
[X]RegEx
#########################
FROM:
Name-123_abcdef.txt
Surname-65345_asdad.txt
Dude-567_qqqq.txt
TO:
Name.txt
Surname.txt
Dude.txt
USE:
Name: [N]
Exte: [E]
Search: (.+?)-.+
Replace: $1
[_]E
[X]RegEx
#########################
You also can utilize one of the "Script"-Plugin:
1.) TC content plugin SCRIPT.WDX (32-Bit only)
http://www.totalcmd.net/plugring/script_wdx.html
Example use Now.vbs (not related to your issue)
http://ghisler.ch/board/viewtopic.php?p=206065#206065
2.) WinScript Advanced (32-Bit und 64-Bit)
http://ghisler.ch/board/viewtopic.php?t=44032
Example use "CurrentDate.vbs" (not related to your issue)
http://ghisler.ch/board/viewtopic.php?t=44057
Name-123_abcdef.txt
Surname-65345_asdad.txt
Dude-567_qqqq.txt
TO:
Name-XXX123_abcdef.txt
Surname-XXX65345_asdad.txt
Dude-XXX567_qqqq.txt
USE:
Name: [N]
Exte: [E]
Search: (.+?-)
Replace: $1XXX
[X]RegEx
#########################
FROM:
Name-123_abcdef.txt
Surname-65345_asdad.txt
Dude-567_qqqq.txt
TO:
Name.txt
Surname.txt
Dude.txt
USE:
Name: [N]
Exte: [E]
Search: (.+?)-.+
Replace: $1
[_]E
[X]RegEx
#########################
You also can utilize one of the "Script"-Plugin:
1.) TC content plugin SCRIPT.WDX (32-Bit only)
http://www.totalcmd.net/plugring/script_wdx.html
Example use Now.vbs (not related to your issue)
http://ghisler.ch/board/viewtopic.php?p=206065#206065
2.) WinScript Advanced (32-Bit und 64-Bit)
http://ghisler.ch/board/viewtopic.php?t=44032
Example use "CurrentDate.vbs" (not related to your issue)
http://ghisler.ch/board/viewtopic.php?t=44057
-
- Junior Member
- Posts: 37
- Joined: 2011-04-01, 21:11 UTC
zupermario wrote:that is "put the file on a folder named as the filename part before the "-" ??
Try
FROM:
Name-123_abcdef.txt
Surname-65345_asdad.txt
Dude-567_qqqq.txt
TO:
Name\Name-123_abcdef.txt
Surname\Surname-65345_asdad.txt
Dude\Dude-567_qqqq.txt
USE:
Name: [N]
Exte: [E]
Search: (.+?)(-.+)
Replace: $1\\$1$2
[_]E
[X]RegEx
-
- Junior Member
- Posts: 37
- Joined: 2011-04-01, 21:11 UTC
Here:
- = just a minus character
.+? = non-greedy any positive number of any characters (non-greedy means that it will look for shortest possible sequence: .+?- will stop at the first minus character if there are more than one)
() - define subgroups $1, $2 etc
So (.+?)(-.+) expression defines two subgroups: first one starts at the beginning of filename and ends before first minus character and second one starts at first minus character and ends at the end of filename.
- = just a minus character

.+? = non-greedy any positive number of any characters (non-greedy means that it will look for shortest possible sequence: .+?- will stop at the first minus character if there are more than one)
() - define subgroups $1, $2 etc
So (.+?)(-.+) expression defines two subgroups: first one starts at the beginning of filename and ends before first minus character and second one starts at first minus character and ends at the end of filename.
Which reminds me:Stefan2 wrote:Replace: $1\\$1$2
Why is there still no documentation about the backslash being the escape character for the replace string in RegEx S&R?
I can't find anything about it in the help file.
TC plugins: PCREsearch and RegXtract
RegEx: A backslash \ starts an Escape sequence.
milo1012 wrote:Which reminds me:Stefan2 wrote:Replace: $1\\$1$2
Why is there still no documentation about the backslash being the escape character for the replace string in RegEx S&R?
I can't find anything about it in the help file.
- Open Multirename tool
- Press F1 key
- Click at "regular expressions" in the sentence "RegEx Now supports regular expressions."
- Read below of "Escape sequences:"
A backslash \ starts an Escape sequence.
Examples for escape sequences:
\\ Finds a backslash.
Is it that you are looking for?
And..... (-.+) looks funny, like an emotion icon

Re: RegEx: A backslash \ starts an Escape sequence.
No, this is just common RegEx syntax. I mean the Replace String when using RegEx, where it seems not documented that you can use e.g.Stefan2 wrote:Is it that you are looking for?
\$1
to print $1 literal and likewise that "\" turns into a single backslash, and so on.
RegEx is just about finding strings, but it's up to a program how it implements referencing subgroups and how to escape such references. That's why it should be explained clearly IMO.
TC plugins: PCREsearch and RegXtract
Erm, no.Stefan2 wrote:If you are enabling the RegEx checkbox for the Replace String to utilize things like '$1',
then you are using RegEx, and the above mentioned help explains that regex syntax.
Again: RegEx is about finding strings. The replacement syntax is something completely different and up to the program.
Just look at e.g. http://www.regular-expressions.info/replacebackref.html
to see the most common different styles.
TC's RegEx help section only explains that you can use $Number to reference subgroups, but not explicitly that you can use the backslash in there too. The backslash is the common escape character/sequence for the expression itself in most RegEx engines, and TC's escape sequence help section explains that very RegEx syntax. But the replacement scheme is a completely different thing, and so you have to "guess" that you can use the backslash it in the replacement string too.
A little explanation in that matter might be advisable, and that's all I wanted to express.
TC plugins: PCREsearch and RegXtract
Regular expressions are both for searching and replacing so both fields change syntax when you enable RegEx (and TC help shows how to reference groups).milo1012 wrote:Again: RegEx is about finding strings. The replacement syntax is something completely different and up to the program.
Just look at e.g. http://www.regular-expressions.info/replacebackref.html
There are some different schemes where different characters are used for referencing groups: \1 (e.g. in Java and JS), $1 (e.g. in Perl and PCRE), maybe some other characters too (who knows).
And just what makes that so clear to you?Stefan2 wrote:If you enable RegEx, then the regex engine is active for the "replacement scheme",
and so the mentioned help about the regex syntax can be used.
I don't know how else to put this, but you obviously don't seem to know that the RegEx expression syntax is one thing, but the replacement syntax does not necessarily needs to use the same rules for escaping.
Using a RegEx is about finding strings, see e.g. the common Unix grep tool. Using a replacement string will use different assumptions in most programs. You might want to try such thing in grep or programs using PCRE.
You know, I wrote my own plug-ins that use PCRE (not the quite new PCRE2), where I'm on my own to implement a replacement syntax, and I didn't use the backslash for escaping, simply because there is no reason for it.
I could point you to different programs that don't use that scheme also, but I don't want to get even more off-topic in this thread.
Just one more thing:
If you follow TC's RegEx help link to the engine's site
http://www.regexpstudio.com/TRegExpr/Help/RegExp_Syntax.html
you won't see any replacement syntax, but only the RegEx syntax, including escape syntax.
You need to navigate to
http://www.regexpstudio.com/TRegExpr/Help/tregexpr_interface.html#tregexpr.substitute
to see the function that Christian used.
But even in there you won't find any explanation concerning escaping subgroups.
Nope, a RegEx is about finding. You probably mean a RexEx engine, but even then you not necessarily have a replacement syntax, see e.g. grep and PCRE.MVV wrote:Regular expressions are both for searching and replacing
Yes, I already showed that in my link above, but like I just explained: PCRE doesn't have a replacement scheme built in. Only PCRE2 started this recently. Same thing in grep.MVV wrote:There are some different schemes where different characters are used for referencing groups: \1 (e.g. in Java and JS), $1 (e.g. in Perl and PCRE).
TC plugins: PCREsearch and RegXtract