Multi Commander Support Forum

Multi Commander => Script => Topic started by: Ulfhednar on December 24, 2016, 16:27:43

Title: Rename profiles accessed by MS?
Post by: Ulfhednar on December 24, 2016, 16:27:43
I see that it is possible to use filters in MS now & maybe dreamed this also applied to rename profiles..?
So far I cannot find anything related to MS calling rename filters though.
Perhaps it is a 'to do'?
If not please point me in the right direction! ;)

Meanwhile I will have to do it the old way,   ;D

Merry Xmas
Title: Re: Rename profiles accessed by MS?
Post by: Ulfhednar on December 25, 2016, 11:08:19
Thought I'd share my 'solution'.  I expect the MS wizards will know a better/optimal way, but this works for me on one or multiple files to clean up/replace  unwanted chars in filenames. ;)

Code: [Select]
//Name cleanup

@var $arr1 = GetSourceSelectedPaths();
@var $items = arrayCount($arr1);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName0;
@var $NewName1;
@var $NewName2;
@var $NewName3;
@var $NewName4;
@var $NewName5;
@var $n1;

for( $n1 = 0; $n1 < $items; $n1++ )
{
  $CurrentNameFullPath = $arr1[ $n1 ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $NewName0 = StrReplace( $OrgName, "_ " , "-" );
  $NewName1 = StrReplace( $NewName0, " m" , " e " );
  $NewName2 = StrReplace( $NewName1, " r" , "R" );
  $NewName3 = StrReplace( $NewName2, " y" , " " );
  $NewName4 = StrReplace( $NewName3, " x" , "m" );
  $NewName5 = StrReplace( $NewName4, "a" , " s" );
 
  RenameFile( $CurrentNameFullPath, $NewName5, "SILENT" );
}

Title: Re: Rename profiles accessed by MS?
Post by: Mathias (Author) on December 27, 2016, 13:05:24
I see that it is possible to use filters in MS now & maybe dreamed this also applied to rename profiles..?
So far I cannot find anything related to MS calling rename filters though.
Perhaps it is a 'to do'?
If not please point me in the right direction! ;)

Meanwhile I will have to do it the old way,   ;D

Merry Xmas
Filters is not new in the release ?
Not sure I get what you want to do ?
Title: Re: Rename profiles accessed by MS?
Post by: Mathias (Author) on December 27, 2016, 13:08:03
Thought I'd share my 'solution'.  I expect the MS wizards will know a better/optimal way, but this works for me on one or multiple files to clean up/replace  unwanted chars in filenames. ;)

Code: [Select]
//Name cleanup

@var $arr1 = GetSourceSelectedPaths();
@var $items = arrayCount($arr1);
@var $CurrentNameFullPath;
@var $OrgName;
@var $NewName0;
@var $NewName1;
@var $NewName2;
@var $NewName3;
@var $NewName4;
@var $NewName5;
@var $n1;

for( $n1 = 0; $n1 < $items; $n1++ )
{
  $CurrentNameFullPath = $arr1[ $n1 ];
  $OrgName = PathGetNamePart( $CurrentNameFullPath );
  $NewName0 = StrReplace( $OrgName, "_ " , "-" );
  $NewName1 = StrReplace( $NewName0, " m" , " e " );
  $NewName2 = StrReplace( $NewName1, " r" , "R" );
  $NewName3 = StrReplace( $NewName2, " y" , " " );
  $NewName4 = StrReplace( $NewName3, " x" , "m" );
  $NewName5 = StrReplace( $NewName4, "a" , " s" );
 
  RenameFile( $CurrentNameFullPath, $NewName5, "SILENT" );
}

(Why do use NewName1 -> 5, ?? why not use the same variable ?? )

In the MultiRename tool you can replace char x with y and so on in the search and replace part
Title: Re: Rename profiles accessed by MS?
Post by: Ulfhednar on December 28, 2016, 10:15:51
Sorry to ruin your Xmas break Mathias!  :o

Originally I wanted to call an existing rename profile (in the same way as a filter) with a MScript.  Couldn't see how to do that.  Filters have an ID to call but I have not found ID tags in the rename dialog & didn't dig deeper. 

Not all files contain all the same items I want to change.  Some have one character to change, others some or all.
I wasn't sure I could apply a single @var to this task.  I expected conflicts.
I concluded that with multiple possible case-sensitive rename actions, I needed to queue them discretely, so gave them different @vars.   
Would a Function concatenate multiple changes...?

As you know I like to cause headaches with MultiScript - I find it therapeutic.   8) :)
Title: Re: Rename profiles accessed by MS?
Post by: Mathias (Author) on December 29, 2016, 14:05:43
Sorry to ruin your Xmas break Mathias!  :o

Originally I wanted to call an existing rename profile (in the same way as a filter) with a MScript.  Couldn't see how to do that.  Filters have an ID to call but I have not found ID tags in the rename dialog & didn't dig deeper. 

Not all files contain all the same items I want to change.  Some have one character to change, others some or all.
I wasn't sure I could apply a single @var to this task.  I expected conflicts.
I concluded that with multiple possible case-sensitive rename actions, I needed to queue them discretely, so gave them different @vars.   
Would a Function concatenate multiple changes...?

As you know I like to cause headaches with MultiScript - I find it therapeutic.   8) :)

I added two new strReplace  MultiScript function in 6.9.1, so doing the thing about or similar should be easier.

Code: [Select]
// Replace every 'a' and every b and c with the substring "Dragon" 
// so if $name is  "abcdef" it will be  "555def"  the replace with can be a substring with many chars. BUT is you include characters there are inlcuded in the replace characters , The result will be strange
$Name = StrReplaceChars( $Name, "abc" , "5" ); 

// This require that Replace pattern and ReplaceWith is the same lenght, the first char in 'replace' will be replaced with the first char in "replacewith" and so on.
$Name = StrReplaceCharsPairs( $Name, "_ mryxa" , "-eR ms" );
Title: Re: Rename profiles accessed by MS?
Post by: Ulfhednar on December 30, 2016, 13:23:22
Thanks Mathias!  :D
New Toys! It's like it's Xmas!  ...oh wait... :P

I will have some fun with these new commands.   8)
Title: Re: Rename profiles accessed by MS?
Post by: AlanJB on January 03, 2017, 18:47:08
Hi Mathias.

Are there plans to add  StrReplaceChars() and StrReplaceCharsPairs() to the documentation?

If so, I feel some editing coming on ;)
Title: Re: Rename profiles accessed by MS?
Post by: Mathias (Author) on January 05, 2017, 11:12:30
Hi Mathias.

Are there plans to add  StrReplaceChars() and StrReplaceCharsPairs() to the documentation?

If so, I feel some editing coming on ;)
Hehe yes.. I just forgot about that..