401
Script / Re: Rename & move/copy
« on: August 28, 2013, 19:37:23 »
Hmm well I might be forgiven for thinking you might write a Java based script from scratch using the Java language....!
January 2024
MultiCommander v13.5 is released!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
$file = $arr[$i];
$s = PathGetFileExtPart( $file );
$name = $prefix + "*" + $s;
$files = FindFiles( $src_path + $name );
$n = arrayCount( $files );
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $file
@var $files;
@var $files1;
@var $n = 0;
//find txt
for( $n = 0; $n < $items; $n++ )
{
$file = $arr[ $n ];
$files = PathGetFileExtPart( $file );
$files1 = FindFiles( $files, "*.txt");
}
You want to rename a folder and then you also want to rename the subitems in that folder before you move them ?
@var $arr3 = GetSourceSelectedPaths();
@var $items3 = arrayCount($arr3);
@var $MoveNameFullPath;
@var $targetPath;
@var $sourceFile;
@var $n3 = 0;
for( $n3 = 0; $n3 < $items3; $n3++ )
{
$MoveNameFullPath = $arr3[ $n3 ];
$targetPath = GetTargetPath();
$sourceFile = $MoveNameFullPath;
MoveFile( $targetPath, $sourceFile );
}
@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;
// regex rename
for( $n = 0; $n < $items; $n++ )
{
$CurrentNameFullPath = $arr[ $n ];
$OrgName = PathGetNamePart( $CurrentNameFullPath );
$result = StrRegExpReplace($OrgName, $re, "$3.$2-$1");
RenameFile( $CurrentNameFullPath, $result, "SILENT" );
}
// move
@var $targetPath;
@var $sourceFile;
{
$CurrentNameFullPath = $arr[ $n ];
$targetPath = GetTargetPath();
$sourceFile = $CurrentNameFullPath;
MoveFile( $targetPath, $sourceFile );
}
@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" );
}
@var $NewName;
@var $NewName2;
{
$CurrentNameFullPath = $arr[ $n ];
$NewName = PathGetNamePart( $CurrentNameFullPath );
$NewName2 = StrReplace( $NewName, "." , "-" );
RenameFile( $arr, $NewName2, "SILENT" );
}
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $targetPath;
@var $sourceFile;
@var $n = 0;
for( $n = 0; $n < $items; $n++ )
{
$CurrentNameFullPath = $arr[ $n ];
$targetPath = GetTargetPath();
$sourceFile = GetSourceFocusPath();
MoveFile( $targetPath, $sourceFile );
}
@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" );
}
$result = StrRegExpReplace($OrgName, $re, "$3.$2-$1");
allowed@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" );
}
((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+)
replace - \1 \2-\3
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "((?:[0-9]+)+)-((?:[0-9]+)+)-((?:[0-9]+)+)";
@var $result;
@var $n = 0;
for( $n = 0; $n < $items; $n++ )
{
$CurrentNameFullPath = $arr[ $n ];
$OrgName = PathGetNamePart( $CurrentNameFullPath );
$result = StrRegExpReplace($OrgName, $re, ".");
RenameFile( $arr, $result, "SILENT" );
}
@var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = ".A[0-9][0-9]B[0-9][0-9].";
@var $result;
@var $n = 0;
for( $n = 0; $n < $items; $n++ )
{
$CurrentNameFullPath = $arr[ $n ];
$OrgName = PathGetNamePart( $CurrentNameFullPath );
$result = StrRegExpReplace($OrgName, $re, ".");
RenameFile( $arr, $result, "SILENT" );
}
"This.String.A02B22.SUBString-ZZZZ" -> "This.String.SUBString-ZZZZ"
...so the regex is definitely not MC friendly.... @var $arr = GetSourceSelectedPaths();
@var $items = arrayCount($arr);
@var $CurrentNameFullPath;
@var $OrgName;
@var $re = "\d+";
@var $result;
@var $n = 0;
for( $n = 0; $n < $items; $n++ )
{
$CurrentNameFullPath = $arr[ $n ];
$OrgName = PathGetNamePart( $CurrentNameFullPath );
$result = StrRegExpReplace($OrgName, $re, "x");
RenameFile( $arr, $result, "SILENT" );
}
((?:[0-9]+)+)_((?:[a-zA-Z]+)+)_((?:[0-9]+)+) -> ((?:[0-9]+)+) ((?:[a-zA-Z]+)+)-((?:[0-9]+)+)