OK, i had something like this in mind:
FROM:
Code: Select all
name2_description1_description2_descriptionX86_v1.2.3.ext
name2_description1_description2_descriptionX86_v1.2.ext
name2_description1_description2_descriptionX86_v1.ext
name2_description1_description2_descriptionX_1.2.3.ext
name2_description1_description2_descriptionX_v1.2.ext
name2_description1_description2_descriptionX_v1.ext
name.description1.description2.descriptionX86.v1.2.3.ext
name.description1.description2.descriptionX86.v1.2.ext
name.description1.description2.descriptionX86.v1.ext
name.description1.description2.descriptionX.1.2.ext
name.description1.description2.descriptionX.v1.2.3.ext
name.description1.description2.descriptionX.v1.ext
TO
Code: Select all
name2 description1 description2 descriptionX86 v1.2.3.ext
name2 description1 description2 descriptionX86 v1.2.ext
name2 description1 description2 descriptionX86 v1.ext
name2_description1_description2_descriptionX_1.2.3.ext
name2 description1 description2 descriptionX v1.2.ext
name2 description1 description2 descriptionX v1.ext
name description1 description2 descriptionX86 v1.2.3.ext
name description1 description2 descriptionX86 v1.2.ext
name description1 description2 descriptionX86 v1.ext
name description1 description2 descriptionX v1.2.3.ext
name.description1.description2.descriptionX.1.2.ext
name description1 description2 descriptionX v1.ext
DO:
USE THIS SCRIPT WITH TESTFILES ONLY/FIRST
The char "v" followed by digits (and dots) until the last dot for the extension is the anchor for this script.
When the "v" as the delimiter is not found the renaming is skipped.
Code: Select all
//v9.90.0304 - 2011-02-13 , + Scripting: Added foreach loops
//
//http://www.xyplorer.com/xyfc/viewtopic.php?p=57514#p57514
//The char "v" followed by digits (and dots) until the last dot for the extension is the anchor for this script.
//When the "v" as the delimiter is not found the renaming is skipped.
//
//
global $FileName, $InStrRev, $Sign;
// $ITEMS = get("SelectedItemsPathNames", "|");
foreach($token, <get SelectedItemsNames |>)
{
$FileName = $token; //ForEach don't set value to *global* vars?!
//split extension:
$Sign = "."; sub "_InStrRev";
$Base = substr($FileName, 0, $InStrRev -1);
$Exte = substr($FileName, $InStrRev);
//split name base part into two parts at "v[:Digits:]":
$Part1 = regexreplace($Base, "(.+?)[_.](v[\d.]+)", "$1");
$Part2 = regexreplace($Base, "(.+?)[_.](v[\d.]+)", "$2");
//only if the regex did match:
if ($Part1 != $Part2)
{
//do replacing in part1:
$Part1 = regexreplace($Part1, "[._]", " ");
//debug:
msg "$FileName<crlf 2>$Part1 $Part2.$Exte<crlf 3>Press cancel to stop this script...",1;
//do the renaming while leave the extension as it is:
rename, "$Part1 $Part2", , "<curpath>\$FileName";
}
}
"_InStrRev" //Function
/*
"_InStrRev" gives last possition of $Sign in $FileName
Syntax:
$Sign = ".";
sub "_InStrRev";
Return: last pos of $Sign in $FileName
*/
global $FileName, $InStrRev, $Sign;
$Index=0;
while($Index < strlen($FileName))
{
If ($FileName==""){break;}
$check = strpos( $FileName, "$Sign", strlen($FileName) - $Index );
If ($check > -1){$InStrRev = $check +1; break;}
$Index++;
}
-----
EDIT:
first try to rename the remaining files too:
Not ready.... needs some tests... use with care...
Code: Select all
//v9.90.0304 - 2011-02-13 , + Scripting: Added foreach loops
global $FileName, $InStrRev, $Sign;
// $ITEMS = get("SelectedItemsPathNames", "|");
foreach($token, <get SelectedItemsNames |>)
{
$FileName = $token; //ForEach don't set value to *global* vars?!
$FilePath = "<curpath>";
//split extension:
$Sign = "."; sub "_InStrRev";
$Base = substr($FileName, 0, $InStrRev -1);
$Exte = substr($FileName, $InStrRev);
//split name base part into two parts at "v[:Digits:]":
$Part1 = regexreplace($Base, "(.+?)[_.](v[\d.]+)", "$1");
$Part2 = regexreplace($Base, "(.+?)[_.](v[\d.]+)", "$2");
//only if the regex did match:
if ($Part1 != $Part2)
{
//do replacing in part1:
$Part1 = regexreplace($Part1, "[._]", " ");
//debug:
//msg "$FileName<crlf 2>$Part1 $Part2.$Exte<crlf 3>Press cancel to stop this script...",1;
//do the renaming:
rename, "$Part1 $Part2", , $FilePath\$FileName;
}
else
{
////////////// ADDITIONAL
//rename files without match criteria "v[:Digits:]" too:
//replace all underscore by an space
rename s, "_/ " , , $FilePath\$FileName;
//replace all dots by an space (you have to reenter the file/ext delimiter)
rename s, "./ " , , $FilePath\$FileName;
}
}
"_InStrRev"
//"_InStrRev" Function gives last possition of $Sign in $FileName
//Syntax: $Sign = "."; sub "_InStrRev"; Return: last pos of $Sign in $FileName
global $FileName, $InStrRev, $Sign;
$Index=0;
while($Index < strlen($FileName))
{
If ($FileName==""){break;}
$check = strpos( $FileName, "$Sign", strlen($FileName) - $Index );
If ($check > -1){$InStrRev = $check +1; break;}
$Index++;
}