Author Topic: File Search Tab: Rename, Multi-Rename  (Read 32414 times)

Crash+Burn

  • Junior Member
  • **
  • Posts: 33
    • View Profile
File Search Tab: Rename, Multi-Rename
« on: October 16, 2013, 23:42:48 »
When attempting a Multi-Rename from files selected within a Search Tab, "Replace Name & Extension" does not work: as soon as you type a dot, or \. (for regex) the file is no longer matched.

Context Menu for File Search Tab, is oddly missing a Rename entry?

GrantSP

  • Active Member
  • ***
  • Posts: 92
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #1 on: October 17, 2013, 01:00:50 »
I could be wrong but, I believe the regexp doesn't work properly even without going through the search tab.

I just tried to perform some regexp, to see what the OP is describing, and I had the same trouble using \ or . even upon files selected from the main file panel. That is without using the search to narrow the selection.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4491
    • View Profile
    • Multi Commander
Re: File Search Tab: Rename, Multi-Rename
« Reply #2 on: October 17, 2013, 07:00:31 »
regexp work in the Multi-Rename tool.

However the Name part and Extension part are handled separately. So there is do "." part to match the extension for.


GrantSP

  • Active Member
  • ***
  • Posts: 92
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #3 on: October 17, 2013, 08:12:49 »
Hmm.
Although I don't use regexp a lot there does seem to be some errors here.

An example of regexp is:
\[.\] matches any single character surrounded by "[" and "]" since the brackets are escaped, for example: "[a]" and "".

Using \ however inside the Multi-Rename tool gives an error message whenever it is used.

Error message is:
regex_error(error_escape): The expression contained an invalid escaped character, or a trailing escape.

If your implementation of regexp uses different methods, perhaps some tooltips inside the tool to assist in their creation would help.
« Last Edit: October 17, 2013, 08:15:16 by GrantSP »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4491
    • View Profile
    • Multi Commander
Re: File Search Tab: Rename, Multi-Rename
« Reply #4 on: October 17, 2013, 08:30:49 »
The regex engine is a so called perl compatible... I have not written it my self, regex is supported by the C++ standard libraries now days and that is the engine that is used. The error messages comes directly from the engine.

Im no regex expert.
But if I have  a filename named "MyFile[A].txt" and in the Multi-Rename under "Search and Replace" I got "\[.\]" and Replace with "B"
and "RegEx" checkbox checked..
it works. It renames file to MyFileB.txt, I do not get an error

Crash+Burn

  • Junior Member
  • **
  • Posts: 33
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #5 on: October 17, 2013, 21:44:07 »
regexp work in the Multi-Rename tool.

However the Name part and Extension part are handled separately. So there is do "." part to match the extension for.
Regex is checked, and it works fine for matching the dot/extension when using [Replace Name & Extension] and a normal tab...
but when doing so from a "File Search" tab you can no longer match the dot of an extension with either regex or not.

GrantSP

  • Active Member
  • ***
  • Posts: 92
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #6 on: October 18, 2013, 02:50:47 »
The regex engine is a so called perl compatible... I have not written it my self, regex is supported by the C++ standard libraries now days and that is the engine that is used. The error messages comes directly from the engine.

Im no regex expert.
But if I have  a filename named "MyFile[A].txt" and in the Multi-Rename under "Search and Replace" I got "\[.\]" and Replace with "B"
and "RegEx" checkbox checked..
it works. It renames file to MyFileB.txt, I do not get an error

My post somehow got mangled and the example I set shows incompletely.
(Mathias : BBCode that the forum uses and regex tags got mixed up but putting a "code" tag arround it fixes the formatting..)

It should be:
Code: [Select]
\[.\] matches any single character surrounded by "[" and "]" since the brackets are escaped, for example: "[a]" and "[b]".
Which means your file named "MyFile[A].txt should be renamed to "MyFile[B].txt.
If it renames it to "MyFileB.txt" then the regex code is treating the "\" character differently to what is expected.
Whether that is bad or not I am not saying. All I am suggesting is a tooltip or other help device to show which expressions ARE used in your code.

Regex is a very peculiar tool, and those that use it probably use it in lots of different ways, in different software. If there are any differences it needs to be shown what they are to avoid any confusion.

@Crash+Burn
I think you might need to be more explicit in your examples.
If I perform a search for some files, and they are then shown in a search tab. I can select them all and start a Multi-Rename using regex. If I use "." as the Find ALL characters should be, and are, selected ready to be changed to the Replace variable.

eg.

File Search for all files that have "__V__1" in the name.
Result is a selection of files displayed in a Search tab panel with that set of characters in their name.
Now I select them all and perform a Multi-Rename on them using regex.

If I set the Find to "." and Replace to A. ALL the characters in the filename and extension are changed to A.
So the resultant files displayed below will look like:
AAAAAAAAAAAAAAA.AAA
AAAAAAAAAAAAAAAAAAAAA.AAA
AA.AAAAAAA
AAAAAAA.AAAAA

Depending on how long the filenames and extensions were in the first place.

If you are expecting something else, then I suspect you might have a different set of expectations to what regex can do.
In my experience "." means ANY CHARACTER.

This all goes back to my original statement that the ACTUAL regex used inside MC should be clearly shown to avoid any such confusion.
« Last Edit: October 18, 2013, 06:56:39 by Mathias (Author) »

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4491
    • View Profile
    • Multi Commander
Re: File Search Tab: Rename, Multi-Rename
« Reply #7 on: October 18, 2013, 07:20:23 »
RegEx in Find/Replace will replace the entire match of the regex with find. If you want to replace some part of the regex match part I think you need some grouping or submatching thing. Im not sure. Im no regex expert.

Code: [Select]
"\[.\]"  then it matches "[A]"  and if you replace that with B.  then you get MyFileB.txt since it replaces the entire match. if you want to replace [<anything>] with [B] then put "[B] in "replace with"I don't see how the engine should possible know that it only should replace the things between the tags.

GrantSP

  • Active Member
  • ***
  • Posts: 92
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #8 on: October 19, 2013, 01:37:08 »
Quote
I don't see how the engine should possible know that it only should replace the things between the tags.

But that's why there is the regex code!

Using the examples discussed.
Code: [Select]
The file MyFile[A].txt is used with the regex code "\[.\]" and then replace it with "B".
What is actually happening here in plain language is:
"Look for the opening and closing brackets with any single character between.
Then only replace the character that occurs between them, not the brackets themselves.
If the resultant filename is MyFileB.txt then the regex is not working, otherwise you might as well just say:
"Find the opening and closing brackets and any single character between them and replace them ALL with "B".

In the regex code the "\" is used to 'escape' the next character from the action performed upon the search result.
So in our examples the "[" and "]" characters are used as part of the SEARCH criteria but not part of the REPLACE action

Crash+Burn

  • Junior Member
  • **
  • Posts: 33
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #9 on: October 19, 2013, 02:02:42 »
Hmm.
Although I don't use regexp a lot there does seem to be some errors here.

An example of regexp is:
\[.\] matches any single character surrounded by "[" and "]" since the brackets are escaped, for example: "[a]" and "".

Using \ however inside the Multi-Rename tool gives an error message whenever it is used.
I haven't had any problems using backslash \ in the multi-rename...

e.g. Given the list of files
opera.exe
opera.dll
opera - Copy[1].exe

  • Regex, [Replace Name]
Find: ^(opera - Copy)(\[(\d)\])$
Replace: $3_$1$2

Result: 1_opera - Copy[1].exe
« Last Edit: October 19, 2013, 02:06:40 by Crash+Burn »

Crash+Burn

  • Junior Member
  • **
  • Posts: 33
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #10 on: October 19, 2013, 02:06:24 »
Although it seems my original supposition above may be incorrect, I can't seem to match the "dot" of a file extension from a regular tab now either. It appears that MC's implementation doesn't have an option that allows for matching the whole filename as a single string - which you would think [Replace Name & Extension] would be.

I honestly don't know what you would use [Replace Name & Extension] for in its current form

given the following file:
everything.exe
Find: e
Replace: b
--> bvbrything.bxb

I would of expected [Replace Name & Extension] to allow access to the whole filename as a single string
thus permitting you to do something like:
everything.exe
Find: thing\.exe$
Replace: one.exe.bak
---> everyone.exe.bak

Now since you have to choose the matching type, of either [Name], [Extension] or [Name & Extension]
and since that choice affects all the Find/Replace fields, it's actually impossible to change filenames AND the extension.
Unless you want to match the same string in both the filename and it's extension... which seems unlikely.

« Last Edit: October 19, 2013, 02:25:58 by Crash+Burn »

GrantSP

  • Active Member
  • ***
  • Posts: 92
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #11 on: October 19, 2013, 02:23:20 »
I have come to realize that the "problem" here lies with the users. (Crash+Burn and me) :(

As it has been said MC uses Perl compatible regex I decided to refresh my understanding of that interpretation.

Where I am expecting the backslash to "escape" the next character from the action performed upon the search items, what it actual does is serve as a metacharacter along with other characters to perform specific actions. Thus the error message I quoted earlier is in fact 100% correct and should have told me my use of "\" was wrong.

So I fall back on my previous comment that a lot of problems may be averted in the future with the addition of some kind of "legend of expressions" that are used in MC.
In the same manner as the "flyout" menu associated with the Multi-Rename tool when the "<" icon is selected.

More examples of user expectations not matching actual experience. :)

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4491
    • View Profile
    • Multi Commander
Re: File Search Tab: Rename, Multi-Rename
« Reply #12 on: October 19, 2013, 10:45:37 »
Although it seems my original supposition above may be incorrect, I can't seem to match the "dot" of a file extension from a regular tab now either. It appears that MC's implementation doesn't have an option that allows for matching the whole filename as a single string - which you would think [Replace Name & Extension] would be.

I honestly don't know what you would use [Replace Name & Extension] for in its current form

given the following file:
everything.exe
Find: e
Replace: b
--> bvbrything.bxb

I would of expected [Replace Name & Extension] to allow access to the whole filename as a single string
thus permitting you to do something like:
everything.exe
Find: thing\.exe$
Replace: one.exe.bak
---> everyone.exe.bak

Now since you have to choose the matching type, of either [Name], [Extension] or [Name & Extension]
and since that choice affects all the Find/Replace fields, it's actually impossible to change filenames AND the extension.
Unless you want to match the same string in both the filename and it's extension... which seems unlikely.

Maybe the [Name and extension] settings should join the filename before doing the rename.
Right now there is code to do rename of name part and code that does rename of extension part. So when the N&E options was select both rename part was run.
I will look into if they the N&E option should join the name or if there should be another option.. but I think it would be safe to join them without breaking anything else.

Mathias (Author)

  • Administrator
  • VIP Member
  • *****
  • Posts: 4491
    • View Profile
    • Multi Commander
Re: File Search Tab: Rename, Multi-Rename
« Reply #13 on: October 19, 2013, 10:50:02 »
I have come to realize that the "problem" here lies with the users. (Crash+Burn and me) :(

As it has been said MC uses Perl compatible regex I decided to refresh my understanding of that interpretation.

Where I am expecting the backslash to "escape" the next character from the action performed upon the search items, what it actual does is serve as a metacharacter along with other characters to perform specific actions. Thus the error message I quoted earlier is in fact 100% correct and should have told me my use of "\" was wrong.

So I fall back on my previous comment that a lot of problems may be averted in the future with the addition of some kind of "legend of expressions" that are used in MC.
In the same manner as the "flyout" menu associated with the Multi-Rename tool when the "<" icon is selected.

More examples of user expectations not matching actual experience. :)

Yes, Some sample of regexp's would probably be needed. Both as tooltip and to on the doc page.
The thing is that I only have very basic knowledge of regexp and looking at it, looks like weeks of learning it. and I don't have the time.. but I will see if I can create some easy samples..

Crash+Burn

  • Junior Member
  • **
  • Posts: 33
    • View Profile
Re: File Search Tab: Rename, Multi-Rename
« Reply #14 on: October 19, 2013, 19:43:00 »
This was one of the best documents I had read (10+ years ago), when I knew nearly nothing on regex  beyond the bare basics. It covers most of the options apart from more advanced syntax. HTML, .txt extension added to permit attachment. It used to be distributed with XNews.
Quote
AUTHOR
       Philip Hazel, EMAIL <IN DOCUMENT, likely not active>
       University Computing Service,
       New Museums Site,
       Cambridge CB2 3QG, England.
       Phone: <IN DOCUMENT, likely not active>

       Copyright (c) 1998 University of Cambridge.
 

You could probably pull some decent examples out of it, without much issue, or redistribute it and keep the author acknowledgement.

For anyone wanting a more thorough overview: regular-expression.info was very good. There's lots of books as well, but I've found most of what I needed I could figure out myself, or refer to the document below, or articles online.
« Last Edit: October 19, 2013, 19:56:18 by Crash+Burn »