Multi Commander > Feature Requests and Suggestions

Name as Folder?

<< < (2/3) > >>

Jungle:
OK. Modified version.

--- Code: ---Log( 1, 10, "Renaming files to %%parent_folder_name%%[_N].*" );

@var $src_path = GetSourcePath();
@var $arr = PathGetParts( $src_path );
@var $name = $arr[0];
@var $prefix = StrReplace( PathGetPathPart( $src_path, 1 ), $name, "" );

@var $n = StrRFind( $prefix, "\\" );

if ( $n > 0 )
{
  $prefix = StrSub( $prefix, $n + 1, StrLen( $prefix ) - $n - 1 );

  @var $i;
  @var $c;
  @var $s;
  @var $file;
  @var $old_file;
  @var $files;
  @var $mask = "*";

  $arr = GetSourceSelectedPaths();

  for ( $i = 0; $i < arrayCount( $arr ); $i++ )
  {
    $file = $arr[$i];

    if ( IsFolder( $file ) )
    {
      continue;
    }

    $s = PathGetNamePart( $file, 1 );
    $n = StrRegExpFind( $s, "\d+$" );

    if ( $n < 0 )
    {
      $s = "";
    }
    else
    {
      $s = StrSub( $s, $n, StrLen( $s ) - $n );
    }

    $name = $prefix + $s + $mask;
    $s = PathGetFileExtPart( $file );
    $name = $name + $s;

    $files = FindFiles( $src_path + $name );
    $n = arrayCount( $files );


    $s = StrReplace( $name, $mask, "" );
    $n = 0;
    $c = 0;
    while( $n < arrayCount( $files ) )
    {
      while( $n < arrayCount( $files ) )
      {
        $old_file = $files[$n];
$old_file = PathGetNamePart( $old_file );

        if ( StrIsEqual( $s, $old_file ) )
        {
          $c++;
          $s = StrReplace( $name, $mask, "_" + numtostr( $c ) );
          $n = 0;
          break;
        }

        $n++;
      }
    }

    RenameFile( $file, $s, "RENAME_RO" );
  }
}
else
{
  Log( 1, 10, "It seems parent folder is root. Renaming impossible." );
}
--- End code ---

Ulfhednar:
Thanks Jungle  :) 
I tried it & used a date named folder & some "img_###.jpg" files.
I found I got
img_0040.jpg
to become
17-04-20130040.jpg

Which is 'almost' what I would like.  I saw you were able to use "_" as a separator in your 1st script.

Obviously I do not know how to write MC script (!!!) but I thought adding it as you have in #66 :

--- Code: --- $s = StrReplace( $name, $mask, "_" + numtostr( $c ) );
--- End code ---
should work.
Looking through it I guessed entering the _ with the $prefix or the $name might deploy the _ correctly.
e.g "_" $prefix,
but it didn't work.


Having looked at the currently posted docs I am unclear what I might do to alter my output string with added fixed characters.  (In this case _). 
I can see that being able to script patterns of characters added to folder names could be really useful for things like image files. 
The scripting of buttons offers me a lot of possibilities & is an interesting tool. But logically, I probably should use the batch rename instead. 

I would appreciate any advice if you have the opportunity.  I'm not seeing what I personally need in the current script documentation.  I'd like a few walk-thrus.  (Maybe that needs to go on the request list for the next release?)







Jungle:
You may replace

--- Code: ---$n = StrRegExpFind( $s, "\d+$" );
--- End code ---

by

--- Code: ---$n = StrRegExpFind( $s, "(_|-|~)?\d+$" );
--- End code ---

where (_|-|~) is a list of characters that precedes numbers.

But using a special rename tool may indeed be a better idea.

Ulfhednar:
Thanks for the explanation Jungle.
I'd looked at that line but don't understand enough MCS syntax to recognize the correct elements yet. :-[

I will run a few tests later - I am pretty sure that for me, the inclusions/adjustments you have made will be faster for my normal routine than the rename tools, so again thanks a lot.  :)

Mathias (Author):
If you run the script from the debugger..  ( Menu > Help > Multi-Script Debugger ) then you can run the script one line at the time and you can see where stuff goes wrong.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version