Multi Commander > Script

Search routine

<< < (4/8) > >>

Mathias (Author):

--- Quote from: 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: ---@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" );
}

--- End code ---
( Or something like that.. code above is NOT tested.. )

--- End quote ---

Ulfhednar:
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.
--- End quote ---

I swapped $OrgName with $CurrentNameFullPath


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

Mathias (Author):
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..


--- Quote from: Ulfhednar on August 06, 2013, 19:51:18 ---Did you say you were going to add permanent line numbers to the debugger?  (That display when debugger is stopped)

--- End quote ---
No. it will not be added.

Ulfhednar:

--- Quote from: Mathias (Author) on August 06, 2013, 21:48:48 ---...Told you I did not run it...

--- End quote ---

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.

Mathias (Author):

--- Quote from: Ulfhednar on August 07, 2013, 09:36:59 ---Is it necessary to include all variables in the { instruction} groups?

--- End quote ---
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


--- Quote from: Ulfhednar on August 07, 2013, 09:36:59 ---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?

--- End quote ---
The value that the debugger show is what the script engine has for that variable.


--- Quote from: Ulfhednar on August 07, 2013, 09:36:59 ---If \d is digit is \a letter?  Wondering about ?\a in this situation.

--- End quote ---
\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.


--- Quote from: Ulfhednar on August 07, 2013, 09:36:59 ---Better start reading a book on PHP if the forms are similar I guess.

--- End quote ---
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. :)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version