OK. Modified version.
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." );
}