Multi Commander > Script

Search routine

<< < (8/8)

Ulfhednar:
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: ---@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" );
 
  }
--- End code ---

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: ---((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+)
--- End code ---
replace -
--- Code: ---\1 \2-\3
--- End code ---

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

Ulfhednar:
Mathias - Thanks to your comment on C++ regex standards &
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: ---@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" );

}

--- End code ---

Switching the match tokens around

--- Code: ---$result = StrRegExpReplace($OrgName, $re, "$3.$2-$1");
--- End code ---
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)

Navigation

[0] Message Index

[*] Previous page

Go to full version