Multi Commander Support Forum

Multi Commander => Script => Topic started by: Ulfhednar on July 26, 2013, 19:11:46

Title: Search routine
Post by: Ulfhednar on July 26, 2013, 19:11:46
Decided to attempt a script  -
I decided to try to script a button to search for todays jpgs

Code: [Select]
MC.FileSearch.Search SEARCHIN="${sourcepath}" SEARCHFOR="*.jpg"
This will get all jpgs in the active pane.  Date & tree-depth aren't pre-loaded.
What I wish to add is the search dialog parameters
a) for today from 00:00:00.
b) to search x subfolder levels.

If it is possible to send values to the search dialog I assume I will need something like
Code: [Select]
@var $t = GetTime();Then I need to import that & ignore hours/minutes values.
can I EXCLUDE= non $t values or StrIsEqual the 't' to select date matches?

Then I'd want to poke that into the search dialog settings....

That's as far as I have got & it shows how little I have of the language logic at the moment.

But if there was a saved/favorite search function I guess I wouldn't need this :)

Title: Re: Search routine
Post by: Mathias (Author) on July 26, 2013, 19:51:19
Actually you are out of luck :)

The Custom Command for FileSearch (http://multicommander.com/docs/customcommands_list#mc.filesearch.search) do not support date/time matches to be added. (It should, I must have forgot to add it, so I will add it for the next version)

You can load/save searches in the FindFiles Dialog with Ctrl+F1 => F10 (save) and F1 => 10 (Load)
But it will not "reset" the now time for time/date filters so it might not help you completely.
Title: Re: Search routine
Post by: Ulfhednar on July 26, 2013, 23:22:34
Guess I'm not really surprised I decided to try the impossible, & so it's back to the drawing board for script ideas.... ;D

Good to know about the F1 - F10 feature I hadn't realized that was in there.  That will be useful. Thanks.

How many other features are there I don't know about, I wonder?  :P
Title: Re: Search routine
Post by: Mathias (Author) on July 28, 2013, 16:10:59
latest Beta Build 1442 has better TIME support for custom command MC.FileSearch.Search

Example

Code: [Select]
MC.FileSearch.Search SEARCHIN="${sourcepath}" SEARCHFOR="*.jpg" TIME="TODAY"
// OR
MC.FileSearch.Search SEARCHIN="${sourcepath}" SEARCHFOR="*.jpg" TIMEFROM="2013-01-01 10:00:00" TIMETO="2013-03-04 12:00:00"
Title: Re: Search routine
Post by: Ulfhednar on July 29, 2013, 17:20:27
Thanks for the info, I will need to try this out!   ;)
Title: Re: Search routine
Post by: Ulfhednar on July 30, 2013, 19:20:25
Continuing my rename & SAR experiments, I'm wondering about regex to MC script transposition.
e.g.
Number & space to number & '.'
((?:[0-9]+)+)\
\1.

I'm stealing Jungles earlier code & using a . :-
$n = StrRegExpFind( $s, ".?\d+$" );

& I've just realized I appear to need to define a button to run this or is there a field I'm missing/misusing that allows me to run a script on a selected file/folder.  Is there a script input window & if not, can I have one to play with in a future build?  :D
Title: Re: Search routine
Post by: Mathias (Author) on July 30, 2013, 21:54:15
Continuing my rename & SAR experiments, I'm wondering about regex to MC script transposition.
e.g.
Number & space to number & '.'
((?:[0-9]+)+)\
\1.

I'm stealing Jungles earlier code & using a . :-
$n = StrRegExpFind( $s, ".?\d+$" );
?.. in regexp \d means any digit.. or what are you asking ?

& I've just realized I appear to need to define a button to run this or is there a field I'm missing/misusing that allows me to run a script on a selected file/folder.  Is there a script input window & if not, can I have one to play with in a future build?  :D
I don't understand..  You can assign a HotKey , Menu button . Button Panel Button and more for any script command you create.. there are 3 buttons to the right in the User command.  where you create the command.  you can not miss it . :)

Title: Re: Search routine
Post by: Ulfhednar on July 31, 2013, 13:05:59
Thanks for responding Mathias.

I was thinking my regex would be replaced by the modified string by Jungle.  But I don't think it targets spaces.
ie
1 2 3 4
to
1.2.3.4

I wanted to test it & edit (as with a sandbox), before creating a button (that didn't work several times!) - short on time... 
Just wanted to select a file/folder, run the script & if good then assign it a button.  Maybe the debugger does this & I haven't figured out how?

I thought there was something like a script test window, (maybe I recall something like that from XYplorer which I tried years ago?)
But I have just looked at my toolbar - the User Commands item shown on MC homepage is not visible!  ???  See attached
So maybe I am missing it!!  :)
Title: Re: Search routine
Post by: Mathias (Author) on July 31, 2013, 13:43:54
Thanks for responding Mathias.

I was thinking my regex would be replaced by the modified string by Jungle.  But I don't think it targets spaces.
ie
1 2 3 4
to
1.2.3.4
Not sure about regexp.  But if you want to replace all space with "." then you can do

$s = StrReplace( $s, " " , "." );

I wanted to test it & edit (as with a sandbox), before creating a button (that didn't work several times!) - short on time... 
Just wanted to select a file/folder, run the script & if good then assign it a button.  Maybe the debugger does this & I haven't figured out how?
You have the MultiScript debugger under the help menu.

But I have just looked at my toolbar - the User Commands item shown on MC homepage is not visible!  ???  See attached
(Think you forgot to upload the attachment.)
The images on the webpage can be old. the UI might have updated.
Title: Re: Search routine
Post by: Ulfhednar on July 31, 2013, 18:53:19
Thanks Mathias
The screen of my tool bar is posted - it shows the 'user commands' menu element is absent on my UI.  Can you not see it?

How do I make the debugger run a script on a file/folder to test the script? 
I need a window that allows me to run a script 'live' if you see what I mean. 

If I understand correctly I must -
 

That is a lot of clicking around the dialogs so I would like a sandbox. (If it doesn't already exist in some form).

If I understand your advice, my script should be

$s = StrReplace( $s, " " , "." ?\d);

But it doesn't seem to work..  :-[


Title: Re: Search routine
Post by: Jungle on July 31, 2013, 19:31:37
Ulfhednar
Custom commands can be created via Configuration menu.
Then you may open multi-script debugger from the Help menu and choose your command in the dropdown list.

To perform some action on a file/folder you should get its path first by using appropriate functions. They are described in on-line doc.
Title: Re: Search routine
Post by: Mathias (Author) on July 31, 2013, 21:26:20
Thanks Mathias
The screen of my tool bar is posted - it shows the 'user commands' menu element is absent on my UI.  Can you not see it?
My browser in my phone was acting up..

If I understand your advice, my script should be

$s = StrReplace( $s, " " , "." ?\d);
If you want to use Regular Expression then use StrRegExpFind, If you want to use a simple Replace substring/character you StrReplace.
You can not use regular expressing in StrReplace.
Title: Re: Search routine
Post by: Ulfhednar on July 31, 2013, 23:26:34
Thanks Jungle & Mathias, that helps.
I see I will have to pre-define my targets etc now.

It is going to take a while for me to grasp this & how the debugger interfaces, but I am now seeing how it will interact with the selected items & the custom commands list.  I hadn't understood the connection properly before. 

I will persevere & see how it goes.
Title: Re: Search routine
Post by: Ulfhednar on August 06, 2013, 18:15:37
For purposes of learning to write a script I have a folder called  -
abc v.1.2

I want
abc v1.2

The idea being that I keep a "." following a numeral, stripping any others.  A simple regex transposition I thought....
Code: [Select]
((?:[a-zA-Z]+)+)\.
-to-
\1<space>


I have made a couple of assumptions:-
  Guessing this is something like
Code: [Select]
$s = StrRegExpFind( $s, "v." , "v", ".?\d");
As I don't know PHP & I don't have examples of regex type formulae for MCS (I tried transposing elements of Jungles script but it's too advanced for me at this point) I have been messing for several hours unsuccessfully with various combinations & assignments & getting nowhere.


I began trying a simple rename -  1.2.3.4 to 1234 & failed. :'( :-[

I managed to grab the name-
Code: [Select]
@var $arr = GetSourceSelectedFileNames();It comes up as an array correctly, then I assumed I would hand the $arr to the rename function (even tho it's technically a string)
Code: [Select]
RenameFile( $arr = StrReplace( $arr, "." , "" ) );
The debugger runs but doesn't red-flag anything (BTW is there a list of error codes somewhere?)
& of course nothing happens.....
 :-[ ???

So I think I need a walkthru or something that helps me define what I need to do in terms of framework & assignments. 
I assume Jungle wasn't born fluent in MCS,  :P so how do I get started with this?  TiA

 
Title: Re: Search routine
Post by: Mathias (Author) on August 06, 2013, 18:47:29
RegExp are a pain. There are many reqex online testers/editor. try one of them they might be helpful when creating regex.

You can not send an entire array into a function that expect a string.. You need to send each item (string) from the array one by one from the array into the function.
Also do not put to much in one line inside each other. the debugger will stop after ever line, so if you got many things in a line then you will not see what went wrong. (You can shorten it afterwards)

Code: [Select]
@var $arr = GetSourceSelectedFileNames();
@var $items = arrayCount($arr);
@var $OrgName;
@var $NewName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $NewName = PathGetNamePart( $CurrentNameFullPath );
  $NewName = StrReplace( $NewName, "." , "" )
 
  RenameFile( $CurrentNameFullPath, $NewName, "SILENT" );
}
( Or something like that.. code above is NOT tested.. )
Title: Re: Search routine
Post by: Mathias (Author) on August 06, 2013, 19:04:22
RegExp are a pain. There are many reqex online testers/editor. try one of them they might be helpful when creating regex.

You can not send an entire array into a function that expect a string.. You need to send each item (string) from the array one by one from the array into the function.
Also do not put to much in one line inside each other. the debugger will stop after ever line, so if you got many things in a line then you will not see what went wrong. (You can shorten it afterwards)

Code: [Select]
@var $arr = GetSourceSelectedFileNames();
@var $items = arrayCount($arr);
@var $OrgName;
@var $NewName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  // The the Filename part only. (Since the TO name in RenameFile does not accept a path)
  $NewName = PathGetNamePart( $CurrentNameFullPath );
  // replace . with empty.
  $NewName = StrReplace( $NewName, "." , "" )
  // Rename current file to a new name. 
  RenameFile( $CurrentNameFullPath, $NewName, "SILENT" );
}
( Or something like that.. code above is NOT tested.. )
Title: Re: Search routine
Post by: Ulfhednar on August 06, 2013, 19:51:18
Thanks for the pointers Mathias.
I will try again.  The regex I posted above works in its' native environment, but I don't mind creating something different for MCS.  Just a question of seeing what I'm doing wrong...in theory.


I note you didn't test the code but I find it interesting you got the same errors as I did: 23 & 1    ;)
I don't feel so bad I failed completely now ;D

Did you say you were going to add permanent line numbers to the debugger?  (That display when debugger is stopped)

Quote
Multi-Script debugger started.
Debugging started.
Debugger attched.  <<Typo you may wish to fix some time>>
Script engine error => Variable $CurrentNameFullPath not found
Script engine error => Failed to process token - "$NewName"
Script engine error - Line : 10, Error : -23 => Parameter wrong type, Code : "$NewName = StrReplace( $NewName, "." , "" )"
Script engine error - Line : 10, Error : -1 => Code : "$NewName = StrReplace( $NewName, "." , "" )"
Debugger detached.

I swapped $OrgName with $CurrentNameFullPath

Code: [Select]
@var $arr = GetSourceSelectedFileNames();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $NewName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath= $arr[ $n ];
  $NewName = PathGetNamePart( $CurrentNameFullPath);
  $NewName = StrReplace( $NewName, "." , "" )
 
  RenameFile( $CurrentNameFullPath, $NewName, "SILENT" );
}
 
It steps thru & shows the name would change without errors.  the script isn't executed (Normal for debugger or should it execute on the selected elements?)  So I'm not there yet.

[I don't want to eat up too much of your time reviewing this however!]
Title: Re: Search routine
Post by: Mathias (Author) on August 06, 2013, 21:48:48
Yes misstyped the definition of the variable name.. copy paste error.  Told you I did not run it.
But the error message is saying what when wrong.. "variable xxx not found.." so you worked it out..

Did you say you were going to add permanent line numbers to the debugger?  (That display when debugger is stopped)
No. it will not be added.

Title: Re: Search routine
Post by: Ulfhednar on August 07, 2013, 09:36:59
...Told you I did not run it...

Yes just kidding around...  :)  I appreciate the help.


Is it necessary to include all variables in the { instruction} groups?
I wonder why it shows a change in the debugger but doesn't pass the change to the active selection.  Is it waiting for other vars to be handled?

Currently I think I will attempt to run 3 lines to emulate the regex.
1 strip "." & leave space
2 place "." following number.
3 remove space following 'v'


If \d is digit is \a letter?  Wondering about ?\a in this situation.

Better start reading a book on PHP if the forms are similar I guess.
Title: Re: Search routine
Post by: Mathias (Author) on August 07, 2013, 11:05:24
Is it necessary to include all variables in the { instruction} groups?
Eh ?  { are for defining a scope. and loops and conditional expressions will execute its scope if the expression is true.
See how the script language works here http://multicommander.com/docs/multiscript/languagesyntax

I wonder why it shows a change in the debugger but doesn't pass the change to the active selection.  Is it waiting for other vars to be handled?
The value that the debugger show is what the script engine has for that variable.

If \d is digit is \a letter?  Wondering about ?\a in this situation.
\d and \a and all other strange combination is regex stuff. You have to google/bing how regex works. I'm not an expert at regular expressions.

Better start reading a book on PHP if the forms are similar I guess.
MultiScript is not PHP.. but it follows the same programming method as any program language like c/c++/javascrfipt/java/php.. men only in its syntax and structure.. not in built in functions.
So you only need the first chapter in any programming book for beginnings. :)
Title: Re: Search routine
Post by: Ulfhednar on August 07, 2013, 15:01:44
I'm OK for regex's (not expert but OK) I like sites like this
http://regexlib.com/ (http://regexlib.com/)
for some ideas.
Regex is just something for me to attempt as I know I could use MC scripts with regex. 

I have been browsing your online docs.  Cannot see anything which says outright what a perfect base script looks like.  Trying to step through the script Jungle made, I can (more or less) see why it does what it does but cannot extrapolate that yet as it has a lot of operations & variables for my untrained eye.

I'm wondering about vars & 'scope' (sorry, I wasn't using correct terminology)
As you can see from the screen shot in the post above, the debugger didn't red-flag anything but it didn't rename the selected folder either. 
It shows the result but doesn't execute the change.  ???
I therefore wondered if the script requires all predefined vars to be included in {} operations before it will execute.
Apart from that I cannot see why it didn't execute...  No obvious elements like RUN or END etc jump out at me

Slightly OT

I noticed the 'regex' box in the mass rename dialog is greyed out.  That would be useful for me to have in the future. 
(It wouldn't teach me the MCS however.) :P

The addition of TIME="TODAY" etc functions in my custom search works well btw
The updated in-line rename works well, hadn't noticed the <ctrl> + <e> or <ctrl> + <l> before.  Useful  ;)

Thanks Mathias.
Title: Re: Search routine
Post by: Mathias (Author) on August 07, 2013, 23:36:14
I'm wondering about vars & 'scope' (sorry, I wasn't using correct terminology)
As you can see from the screen shot in the post above, the debugger didn't red-flag anything but it didn't rename the selected folder either. 
That is because there is no script error.  but I think you are sending the wrong data into RenameFile(...)
Look at the doc http://multicommander.com/docs/multiscript/functions/filesystem#renamefile and and the description of the parameters and what you send, and see if you can see it. :)
 
I therefore wondered if the script requires all predefined vars to be included in {} operations before it will execute.
Apart from that I cannot see why it didn't execute...  No obvious elements like RUN or END etc jump out at me
The { } are "scopes" for loops or other conditional expressions..  For example if the expression inside an if( ... ) is true the scope belonging to the if is executed. else it is not.
and variables that are defined inside a scope only exists inside that scope. if variable are define in the "global" space then they are accessible by all.
you can write BEGIN / END instead of { } for example
if( $b )
BEGIN
 ...
END

But only boring languages like basic is using that syntax.. { } is used by all modern languages like c/c++/java/js/php and so on.

Title: Re: Search routine
Post by: Ulfhednar on August 08, 2013, 16:12:25
I have finally grasped which function/call & which token arrangement was needed to get my initial script to apply itself!

Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $NewName = StrReplace( $OrgName, "." , "" );
 
  RenameFile( $arr, $NewName, "SILENT" );
  }

Now all I have to do is build my regex! :P
I am beginning to see how the different instructions need to be addressed.   

I wonder if there is already a good way to hi-lite the text for ease of editing (I've found with notepad++ I can save as a codepage & get coloured results, eg:- as .pl or .php), which helps me at the moment.

Thanks for your time & tuition Mathias.   :)

*
For regex you mention StrRegExpFind is there also StrRegExpReplace? (If so I haven't seen it in the docs) I am currently assuming that the the find command will then invoke the regex to do any necessary editing.
Title: Re: Search routine
Post by: Mathias (Author) on August 08, 2013, 16:29:55
I wonder if there is already a good way to hi-lite the text for ease of editing (I've found with notepad++ I can save as a codepage & get coloured results, eg:- as .pl or .php), which helps me at the moment.
Well use an external editor is the option for that.  The built in editor in MC will not support syntax coloring anytime soon. cost so much (in time) to include an edit that support that.

For regex you mention StrRegExpFind is there also StrRegExpReplace? (If so I haven't seen it in the docs) I am currently assuming that the the find command will then invoke the regex to do any necessary editing.
Only functions you see in doc is there. or in release note for latest beta version if it is a new function.. after final release doc is updated. 
Title: Re: Search routine
Post by: Ulfhednar on August 08, 2013, 17:03:36
Quote
syntax coloring
OK no problem.  I can use my current workaround.  ;)

Quote
new function
OK, well I am currently hoping something like the following would work, but it doesn't seem to...

Code: [Select]
$NewName = StrReplace( $OrgName, "{((?:[0-9]+)+)\ }", "{((?:[0-9]+)+)\.}");
Is it just my lack of skill or StrReplace won't accept a regex at all?
Title: Re: Search routine
Post by: Mathias (Author) on August 08, 2013, 17:25:07
Is it just my lack of skill or StrReplace won't accept a regex at all?
StrReplace replaces substrings.
Title: Re: Search routine
Post by: Ulfhednar on August 09, 2013, 18:33:40
OK thanks Mathias.
I will have to do more research.  ;)
I can envisage a multiple file/folder sequence with several routines employed - be nice to get it to work. :P

& OT (but still about regexs!)
Is the greyed out regex box in the mass rename dialog temporary?
Title: Re: Search routine
Post by: Mathias (Author) on August 10, 2013, 15:50:55
& OT (but still about regexs!)
Is the greyed out regex box in the mass rename dialog temporary?

It is planed to support regex in the search part in the search and replace section. But I have not had the time too add it.

Title: Re: Search routine
Post by: Ulfhednar on August 11, 2013, 18:34:17
 
It is planed to support regex in the search part in the search and replace section. But I have not had the time too add it.

Thanks for the update Mathias.  I will continue tearing my hair out with scripting trials while I wait.  :D
Title: Re: Search routine
Post by: Mathias (Author) on August 17, 2013, 17:50:03
It is planed to support regex in the search part in the search and replace section. But I have not had the time too add it.

Thanks for the update Mathias.  I will continue tearing my hair out with scripting trials while I wait.  :D

Build 1469 do now support it
Title: Re: Search routine
Post by: Ulfhednar on August 18, 2013, 15:29:31
I have begun looking at the MC regex function.
I wonder if this is not an acceptable regex -
Code: [Select]
((?:[0-9]+)+)ie: -  find numbers, can be any number of numerals in a group.
Same for letters
Code: [Select]
((?:[a-zA-Z]+)+)
MC doesn't seem to accept this format. 
I see your example
Code: [Select]
<str> StrRegExpReplace(<str>, <regex>, <replaceWith>, [int startPos] )
example

@var $str = "This.String.A02B22.SUBString-ZZZZ";
@var $re = ".A[0-9][0-9]B[0-9][0-9]."";
@var $result = StrRegExpReplace($str, $re, "XX");
 // result is This.StringXXSUBString-ZZZZ

 - specifies quantity of individual characters.  'Hungry' expression is defined differently in MC?

For my experiment I had been thinking of changing a folder date format, e.g. :-
10-05-1989 -> 10.05.1989
Code: [Select]
((?:[0-9]+)+)-((?:[0-9]+)+)   ->    ((?:[0-9]+)+).((?:[0-9]+)+)or
10_May_1989 -> 10 May 1989
Code: [Select]
((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+) ->     ((?:[0-9]+)+) ((?:[a-zA-Z]+)+) ((?:[0-9]+)+)
   
I tried: -
Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName;
@var $re = "((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)";
@var $str = $OrgName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $NewName = StrRegExpReplace($str, $re, ".");
 
  RenameFile( $arr, $NewName, "SILENT" );
  }

But I get - Error : -23 => Parameter wrong type or in the mass rename - 'invalid characters' msg
I had the regex's working  outside MC - but they don't work in the mass rename or the script (yet)   :-[


Title: Re: Search routine
Post by: Mathias (Author) on August 18, 2013, 16:00:09
I have begun looking at the MC regex function.
I wonder if this is not an acceptable regex -
Code: [Select]
((?:[0-9]+)+)
Don't know. I'm not a regex expert. I just use the regex libraries that is included in the C++11 standard and that regex engine should be mostly perl regex compatible
MC doesn't seem to accept this format. 
I see your example
Code: [Select]
<str> StrRegExpReplace(<str>, <regex>, <replaceWith>, [int startPos] )
example

@var $str = "This.String.A02B22.SUBString-ZZZZ";
@var $re = ".A[0-9][0-9]B[0-9][0-9]."";
@var $result = StrRegExpReplace($str, $re, "XX");
 // result is This.StringXXSUBString-ZZZZ

 - specifies quantity of individual characters.  'Hungry' expression is defined differently in MC?
Hungry ?  The above example works. It is takes from my automated unittests.

For my experiment I had been thinking of changing a folder date format, e.g. :-
10-05-1989 -> 10.05.1989
Code: [Select]
((?:[0-9]+)+)-((?:[0-9]+)+)   ->    ((?:[0-9]+)+).((?:[0-9]+)+)or
10_May_1989 -> 10 May 1989
Code: [Select]
((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+) ->     ((?:[0-9]+)+) ((?:[a-zA-Z]+)+) ((?:[0-9]+)+)
Don't think you can do that... because the matching regex will be replaced with the replaceWith string.
You can not replace with another regex.

I tried: -
Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName;
@var $re = "((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)";
@var $str = $OrgName;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $NewName = StrRegExpReplace($str, $re, ".");
 
  RenameFile( $arr, $NewName, "SILENT" );
  }

But I get - Error : -23 => Parameter wrong type or in the mass rename - 'invalid characters' msg
I had the regex's working  outside MC - but they don't work in the mass rename or the script (yet)   :-[
What row did it not like ?
Hmm should you not use $OrgName for StrRegExpReplace ?
And I guess the error is for RenameFile(..) You can still not send an entire array into that. first paramter should be a string that is the is full target path of the file.

if you get invalid char in multirename then you got an invalid char into the file name like :| or some other invalid character.

Title: Re: Search routine
Post by: Ulfhednar on August 18, 2013, 16:47:26
I added a couple of screen shots above to help explain what is happening with mass rename & the regex's.
Debug error was row 13 then 14 when I used $Orgname

(I'm no expert I only know enough to cause trouble!) Hungry:- + forces regex engine to keep looking for matches so
Code: [Select]
((?:[0-9]+)+)should find any combination of digits.  Useful for dates etc where you may have 1-12-1980
Code: [Select]
((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)should match that sequence.
In your example you predefined the # of digits with [0-9] [0-9], if it works with + you can (in theory!) match more than the 2 digits without defining multiple [0-9]s. 

If I use $Orgname I think I drop part of the sequence which links to $newname, maybe I need to have 2 {....} operations defined, one to run the regex, then the next to take the result & use it to rename.  ???

My bad  - I wasn't thinking replace regex with regex but how the groups would appear as a regex (trying out variations in mass rename & confusing myself!)

Thanks for your time Mathias.
Title: Re: Search routine
Post by: Ulfhednar on August 18, 2013, 17:33:10
Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, ".");
 
  RenameFile( $arr, $result, "SILENT" );
 
  }

Seems better - no errors but not renaming.  Will keep trying.

Update
Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = ".A[0-9][0-9]B[0-9][0-9].";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, ".");
 
  RenameFile( $arr, $result, "SILENT" );
 
  }

changes
Code: [Select]
"This.String.A02B22.SUBString-ZZZZ" ->  "This.String.SUBString-ZZZZ"...so the regex is definitely not MC friendly....  :'(
I will need to find out how this system handles the 'hungry' (greedy) operation ::)

As it is the regex I have used would match all combos of 1-12-123; 123-1-12; 1234-12-123 etc so it would be handy to transpose this into the MC-friendly form.

OT -
what do I do to access multiple selections?  At the moment this will only do the first of any selected group.  I'm guessing it's related to $n.

Update 2

Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "\d+";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, "x");
 
  RenameFile( $arr, $result, "SILENT" );
}

Will change multiple digits but won't retain the initial sequence
1.23.234
becomes x.x.x

I want to pass the original string back modifying only certain characters. 
As in  eg -
Code: [Select]
((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+) ->     ((?:[0-9]+)+) ((?:[a-zA-Z]+)+)-((?:[0-9]+)+)
10_May_1980 -> 10 May-1980

I suspect I'm not going to be able to do this.    :(
Title: Re: Search routine
Post by: Mathias (Author) on August 18, 2013, 22:42:49
The rename will never work because you are still using $arr in rename file. That will not work.

RenameFile($arr, $result, "SILENT" );

RenameFile(...) does not accept an array.. it wants a string.

What you trying to do will never work, you can not insert a regex in the replace with part. There is no way for it to match stuff like that.
There no way the engine should understand how match that.

Maybe use the StrRegExFind and from that you get at what position the regex match start. and from there you can get the substring and rebuild the string and replace the part you want manually.
Or you can also loop the string and check character by character and if  you find a - or _ of after a number you replace it.
But then you are not using any cool regexp.

Regex engine in MC is following the regex standard. Think it is called ECMA-262 .. What I understand it is the same as perl uses.
MC does not use any special own regex. it is build into the C++ language as of the C++11 Standard.
But regex are written different depending on what you want to do. and there are 100 ways to do the same thing.

Title: Re: Search routine
Post by: Ulfhednar on August 19, 2013, 00:01:05
Thanks Mathias.
I got confused with $arr - when it was present the script completed one pass, but not the rest of the selection.  (As you must realize).
So I left $arr in order to get the operation to complete & thus find out which part of the regex would work. 

I started using perl type commands but as you say the StrRegExpReplace function won't allow me to do a 'batch' of separate ops.

Took me a while to see which string was the right one with which to replace $arr.  But I now have a better array usage!
 
This will make changes to multiple selections now (not what I want of course but better from a script point of view.) -

Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "\w.";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, " ");
 
  RenameFile( $CurrentNameFullPath, $result, "SILENT" );
 
  }

I cannot use ( ) within the $re define multiple segments, soI think I would have to do a loop of repeat operations to change each element individually.  Quite frustrating when I can run the regex's I posted in a text editor on text & get the right result.   

Regular Expression Editor (RegExpEditor), amongst others, on sourceforge could be useful for regex types.


Well I guess that is enough headache for one day.   ;)

+++

Update
Thought I'd add the regex I was using to change the date field I mentioned above for clarity.  (I was showing the whole string as regex transpositions instead of in -> out)
10_May_1989 -> 10 May 1989
find -
Code: [Select]
((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+)replace -
Code: [Select]
\1 \2-\3
I think I can see a way for each \#<match> for be given its' own instruction.  More headaches req'd.

The main advance for me here is the visualization of matrices in your script.  I was thinking more DOS Basic & linear commands.  Matrix application is more dynamic of course.  So thanks for forcing me down that road.   ;D
Title: Re: Search routine
Post by: Ulfhednar on August 20, 2013, 23:18:39
Mathias - Thanks to your comment on C++ regex standards &
http://www.cplusplus.com/reference/regex/match_replace/ (http://www.cplusplus.com/reference/regex/match_replace/)

I was able to transpose my original regex into a compatible format, the $token & trial & error gave me my desired date mod
10_May_1876  ->  10.May-1876

That + your earlier help on the script writing gave me a handy button for renaming date named folders: -

Code: [Select]
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "([0-9]+)_([a-zA-Z]+)_([0-9]+)";
@var $result;
@var $n = 0;

for( $n = 0; $n < $items; $n++ )
{
  $CurrentNameFullPath = $arr[ $n ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $result = StrRegExpReplace($OrgName, $re, "$3.$2-$1");
 
  RenameFile( $CurrentNameFullPath, $result, "SILENT" );

}

Switching the match tokens around
Code: [Select]
$result = StrRegExpReplace($OrgName, $re, "$3.$2-$1");allowed
10_May_1876  ->  1876.May-10

Obviously this opens up a great deal of possibilities for the regex function in my script experiments.  (& anyone else who may need to use regexs....)


OT
FYI I don't seem to be able to save scripts in the debugger anymore - New / F1 don't work / greyed-out (3.3 build 1470)