Code: Select all
//Created : 2022-05-11
//Modified: 2022-07-12
//Function: Rename selected items with selected item name in another pane
//Version : v1.6
//Handle .ini file
$iniFile = self("path") . "\" . self("base") . "\" . "INI" . "\" . "RegexRenameV1.6" . ".ini";
//Write .ini file if missing
if (exists($iniFile) != 1) {
$iniContent = <<<'>>>'
//History
[LastQuery]
Last=(.*\\)(.*)(0530)(.*)(....)//$2Number<#1>卍(.*\\)(.*)(0530)(.*)(....)//Number<#1>$2$3
//Save use Unicode
LastQuery=
>>>;
writefile($iniFile, $iniContent, , "tu");
}
//Get .ini file entries
$LastQuery = getkey("Last", "LastQuery", $iniFile);
//Get the last query (Can't use <.> etc for some words)
$LastQuery1 = gettoken($LastQuery, 1, '卍', "t");
//Replace separator with "|"
$LastQuery =replace($LastQuery, "卍", "|");
//Notes
$notes = "";
$notes = <<<'>>>'
Regular expression:
(.*\\)(.*)(0530)(.*)(....)
(.*\\)(.mar)(.*)(12)(....)
Regular expression matches:
$2
$2$3
Syntax for increments:
<#1> = 1, 2, ... 222 ...
<#01> = 01, 12, ... 102 ...
<#001> = 001, 088, ... 166 ...
Examples:
(.*\\)(.*)(0530)(.*)(....)//$2Number<#1>
D:\Test\Test0530list.txt -> D:\Test\TestNumber1.txt
(.*\\)(.*)(0530)(.*)(....)//$2$4Number<#1>
D:\Test\Test0530list.txt -> D:\Test\TestlistNumber1.txt
>>>;
//Selected item of another pane
$selectedItem = get("Item", i);
//Input
$part = input("Rename", "$notes", "$LastQuery1", 5:=500, 7:=$LastQuery);
//get // the previous fragment
$regex = gettoken($part, 1, '//', "t");
//get // the following fragment
$partB = gettoken($part, 2, '//', "t");
//If no regular fragment is entered, the regular fragment is $2$3$4
if(!regexmatches($partB, "(\$\d)")) {$replace = "$2$3$4";}
//If no regex is entered
if($partB == "") {$partB = $regex; $case = "1"}
//Get number for increments
if(regexmatches($partB, "<#(\d*)>")) {$num = regexmatches($partB, "<#(\d*)>"); $num = regexreplace($num, "<#(\d*)>", "$1");}
$num2 = $num;
//If a regular fragment is entered, the regular fragment is the entered fragment
if(regexmatches($partB, "(\$\d)")) {$replace = regexmatches($partB, "(\$\d)");}
//Regularly get the fragment name
$replace = replace($replace, "|", "");
$itemName = regexreplace("$selectedItem", "$regex", "$replace");
$partB = regexreplace($partB, "(\$\d)(\$\d)(\$\d)", "$itemName");
$partB = regexreplace($partB, "(\$\d)(\$\d)", "$itemName");
$partB = regexreplace($partB, "(\$\d)", "$itemName");
//If the regex does not get a matching filename, exit and alert
if($itemName == $selectedItem) {end '1==1', "Does not match the name, please check the input!";}
//Get a list of selected files
$list = report("{fullname}<crlf>",1);
$renamePreview = "";
foreach($item, $list, "<crlf>", e) {
//Get the suffix of the currently $item
$itemExt =gpc("$item", "ext");
//Combine and stack
$part2 = regexreplace($partB, "<#(\d*)>", "$num");
$renamePreview .= $part2 . ".$itemExt<crlf>";
//Set numbers
$num++;
//Format number
foreach($item2, "1|2", "|") {
if(regexreplace($num2, "0(\d)") == "") {$num = format($num, "00"); break;}
if(regexreplace($num2, "0(\d)(\d)") == "") {$num = format($num, "000"); break;}
}
}
//Batch rename
rename l, $renamePreview, p, $list, 64;
//Save history
$count = "1";
$newLastQuery = "";
foreach($lastQ, "$LastQuery", "|", "e") {
//If $part is equal to the $item, set $lastQ = "";
if($part == $lastQ) {$lastQ = ""}
//Stack
if $lastQ != "" {$newLastQuery .= "$lastQ" . "卍";}
//$count +1
$count++;
//Break if number equals 15
if $count == "15" {break;}
}
//
if($case != "1") {
//Merge entered value, old value
$newLastQuery = "$part" . "卍" . "$newLastQuery";
//Write the merged values to the ini file
setkey $newLastQuery, "Last", "LastQuery", $iniFile;
}
Code: Select all
//Created : 2022-05-11
//Modified: 2022-07-12
//Function: Rename selected items with full path from clipboard
//Version : v1.6
//Handle .ini file
$iniFile = self("path") . "\" . self("base") . "\" . "INI" . "\" . "RegexRenameV1.6" . ".ini";
//Write .ini file if missing
if (exists($iniFile) != 1) {
$iniContent = <<<'>>>'
//History
[LastQuery]
Last=(.*\\)(.*)(0530)(.*)(....)//$2Number<#1>卍(.*\\)(.*)(0530)(.*)(....)//Number<#1>$2$3
//Save use Unicode
LastQuery=
>>>;
writefile($iniFile, $iniContent, , "tu");
}
//Get .ini file entries
$LastQuery = getkey("Last", "LastQuery", $iniFile);
//Get the last query (Can't use <.> etc for some words)
$LastQuery1 = gettoken($LastQuery, 1, '卍', "t");
//Replace separator with "|"
$LastQuery =replace($LastQuery, "卍", "|");
//Notes
$notes = "";
$notes = <<<'>>>'
Regular expression:
(.*\\)(.*)(0530)(.*)(....)
(.*\\)(.mar)(.*)(12)(....)
Regular expression matches:
$2
$2$3
Syntax for increments:
<#1> = 1, 2, ... 222 ...
<#01> = 01, 12, ... 102 ...
<#001> = 001, 088, ... 166 ...
Examples:
(.*\\)(.*)(0530)(.*)(....)//$2Number<#1>
D:\Test\Test0530list.txt -> D:\Test\TestNumber1.txt
(.*\\)(.*)(0530)(.*)(....)//$2$4Number<#1>
D:\Test\Test0530list.txt -> D:\Test\TestlistNumber1.txt
>>>;
//Full path from clipboard
$clipItem = gettoken("<clipboard>", 1, "<crlf>", "t");
//Input
$part = input("Rename from current clipboard: <crlf>$clipItem", "$notes", "$LastQuery1", 5:=500, 7:=$LastQuery);
//get // the previous fragment
$regex = gettoken($part, 1, '//', "t");
//get // the following fragment
$partB = gettoken($part, 2, '//', "t");
//If no regular fragment is entered, the regular fragment is $2$3$4
if(!regexmatches($partB, "(\$\d)")) {$replace = "$2$3$4";}
//If no regex is entered
if($partB == "") {$partB = $regex; $case = "1"}
//Get number for increments
if(regexmatches($partB, "<#(\d*)>")) {$num = regexmatches($partB, "<#(\d*)>"); $num = regexreplace($num, "<#(\d*)>", "$1");}
$num2 = $num;
//If a regular fragment is entered, the regular fragment is the entered fragment
if(regexmatches($partB, "(\$\d)")) {$replace = regexmatches($partB, "(\$\d)");}
//Regularly get the fragment name
$replace = replace($replace, "|", "");
$itemName = regexreplace("$clipItem", "$regex", "$replace");
$partB = regexreplace($partB, "(\$\d)(\$\d)(\$\d)", "$itemName");
$partB = regexreplace($partB, "(\$\d)(\$\d)", "$itemName");
$partB = regexreplace($partB, "(\$\d)", "$itemName");
//If the regex does not get a matching filename, exit and alert
if($itemName == $clipItem) {end '1==1', "Does not match the name, please check the input!";}
//Get a list of selected files
$list = report("{fullname}<crlf>",1);
$renamePreview = "";
foreach($item, $list, "<crlf>", e) {
//Get the suffix of the currently $item
$itemExt =gpc("$item", "ext");
//Combine and stack
$part2 = regexreplace($partB, "<#(\d*)>", "$num");
$renamePreview .= $part2 . ".$itemExt<crlf>";
//Set numbers
$num++;
//Format number
foreach($item2, "1|2", "|") {
if(regexreplace($num2, "0(\d)") == "") {$num = format($num, "00"); break;}
if(regexreplace($num2, "0(\d)(\d)") == "") {$num = format($num, "000"); break;}
}
}
//Batch rename
rename l, $renamePreview, p, $list, 64;
//Save history
$count = "1";
$newLastQuery = "";
foreach($lastQ, "$LastQuery", "|", "e") {
//If $part is equal to the $item, set $lastQ = "";
if($part == $lastQ) {$lastQ = ""}
//Stack
if $lastQ != "" {$newLastQuery .= "$lastQ" . "卍";}
//$count +1
$count++;
//Break if number equals 15
if $count == "15" {break;}
}
//
if($case != "1") {
//Merge entered value, old value
$newLastQuery = "$part" . "卍" . "$newLastQuery";
//Write the merged values to the ini file
setkey $newLastQuery, "Last", "LastQuery", $iniFile;
}
Code: Select all
//Created : 2022-05-11
//Modified: 2022-07-12
//Function: Enter a full item path to rename the selected items
//Version : v1.6
//Handle .ini file
$iniFile = self("path") . "\" . self("base") . "\" . "INI" . "\" . "RegexRenameV1.6" . ".ini";
//Write .ini file if missing
if (exists($iniFile) != 1) {
$iniContent = <<<'>>>'
//History
[LastQuery]
Last=(.*\\)(.*)(0530)(.*)(....)//$2Number<#1>卍(.*\\)(.*)(0530)(.*)(....)//Number<#1>$2$3
//Save use Unicode
LastQuery=
>>>;
writefile($iniFile, $iniContent, , "tu");
}
//Get .ini file entries
$LastQuery = getkey("Last", "LastQuery", $iniFile);
//Get the last query (Can't use <.> etc for some words)
$LastQuery1 = gettoken($LastQuery, 1, '卍', "t");
//Replace separator with "|"
$LastQuery =replace($LastQuery, "卍", "|");
//Notes
$notes = "";
$notes = <<<'>>>'
Regular expression:
(.*\\)(.*)(0530)(.*)(....)
(.*\\)(.mar)(.*)(12)(....)
Regular expression matches:
$2
$2$3
Syntax for increments:
<#1> = 1, 2, ... 222 ...
<#01> = 01, 12, ... 102 ...
<#001> = 001, 088, ... 166 ...
Examples:
(.*\\)(.*)(0530)(.*)(....)//$2Number<#1>
D:\Test\Test0530list.txt -> D:\Test\TestNumber1.txt
(.*\\)(.*)(0530)(.*)(....)//$2$4Number<#1>
D:\Test\Test0530list.txt -> D:\Test\TestlistNumber1.txt
>>>;
//Input
$fullpath = input("Input", "Enter a full item path", "", 5:=500, 7:=);
//Input
$part = input("Rename", "$notes", "$LastQuery1", 5:=500, 7:=$LastQuery);
//get // the previous fragment
$regex = gettoken($part, 1, '//', "t");
//get // the following fragment
$partB = gettoken($part, 2, '//', "t");
//If no regular fragment is entered, the regular fragment is $2$3$4
if(!regexmatches($partB, "(\$\d)")) {$replace = "$2$3$4";}
//If no regex is entered
if($partB == "") {$partB = $regex; $case = "1"}
//Get number for increments
if(regexmatches($partB, "<#(\d*)>")) {$num = regexmatches($partB, "<#(\d*)>"); $num = regexreplace($num, "<#(\d*)>", "$1");}
$num2 = $num;
//If a regular fragment is entered, the regular fragment is the entered fragment
if(regexmatches($partB, "(\$\d)")) {$replace = regexmatches($partB, "(\$\d)");}
//Regularly get the fragment name
$replace = replace($replace, "|", "");
$itemName = regexreplace("$fullpath", "$regex", "$replace");
$partB = regexreplace($partB, "(\$\d)(\$\d)(\$\d)", "$itemName");
$partB = regexreplace($partB, "(\$\d)(\$\d)", "$itemName");
$partB = regexreplace($partB, "(\$\d)", "$itemName");
//If the regex does not get a matching filename, exit and alert
if($itemName == $fullpath) {end '1==1', "Does not match the name, please check the input!";}
//Get a list of selected files
$list = report("{fullname}<crlf>",1);
$renamePreview = "";
foreach($item, $list, "<crlf>", e) {
//Get the suffix of the currently $item
$itemExt =gpc("$item", "ext");
//Combine and stack
$part2 = regexreplace($partB, "<#(\d*)>", "$num");
$renamePreview .= $part2 . ".$itemExt<crlf>";
//Set numbers
$num++;
//Format number
foreach($item2, "1|2", "|") {
if(regexreplace($num2, "0(\d)") == "") {$num = format($num, "00"); break;}
if(regexreplace($num2, "0(\d)(\d)") == "") {$num = format($num, "000"); break;}
}
}
//Batch rename
rename l, $renamePreview, p, $list, 64;
//Save history
$count = "1";
$newLastQuery = "";
foreach($lastQ, "$LastQuery", "|", "e") {
//If $part is equal to the $item, set $lastQ = "";
if($part == $lastQ) {$lastQ = ""}
//Stack
if $lastQ != "" {$newLastQuery .= "$lastQ" . "卍";}
//$count +1
$count++;
//Break if number equals 15
if $count == "15" {break;}
}
//
if($case != "1") {
//Merge entered value, old value
$newLastQuery = "$part" . "卍" . "$newLastQuery";
//Write the merged values to the ini file
setkey $newLastQuery, "Last", "LastQuery", $iniFile;
}