Compares the file names of the list files

Discuss and share scripts and script files...
Post Reply
Norn
Posts: 415
Joined: 24 Oct 2021 16:10

Compares the file names of the list files

Post by Norn »

Code: Select all

//Created : 2022-05-01
//Modified: 2022-09-04
//Function: Cut a segment of the filename of the list items for comparison, comments the same items with the same number
//Version : v2.2

//Enter the start and end positions of the crop
 $substrS = input("Enter starting position of the crop<crlf>For example 0, 5 or -10", , "0", 5:=300, 7:='0');
 $substrL = input("Enter the end position<crlf>For example 10, 25 or -2", , "300", 5:=300, 7:='350');
//Preview
 $curname = substr("<curname>", $substrS, $substrL);
 if $curname == "" {$curname = "No files is selected and cannot preview";}
 $confirm = confirm("Cropped filenames preview:<crlf><curname><crlf>$curname");
 if $confirm == "0" {end '1==1';}
 
 
 
//Get the current list items
 $List = report("{fullname}<crlf>", 0);
 $Num = "1";
 
 
 
//Each item of the list
 foreach($Item, $List, "<crlf>") {
//Get base filename and cut a segment
 $ItemBase = gpc($Item, "base");
 $ItemBase = substr("$ItemBase", $substrS, $substrL);
//Replace some regular elements
 $ItemBase = replace($ItemBase, "|", "");
 $ItemBase = replacelist($ItemBase, " |[|]|(|)|+", "", "|");
 
//Get the comment of $Item
 $cmt = tagitems("cmt", , "$Item", 1);
//Increments
 if($case == "2") {$Num++; $case = "";}
 
//Exclude computed files
 selectitems $Item;
 sel "+1";
 sel +, 100000;
 $List = report("{fullname}<crlf>", 1);
 
 
 
//Each item of the list(Exclude computed files)
    foreach($Item2, $List, "<crlf>") {
//Get base filename and cut a segment
    $ItemBase2 = gpc($Item2, "base");
	//$ItemBase2 = substr("$ItemBase2", $substrS, $substrL);
//Replace some regular elements
    $ItemBase2 = replace($ItemBase2, "|", "");
	$ItemBase2 = replacelist($ItemBase2, " |[|]|(|)|+", "", "|");
	
	
	
//If $ItemBase2 = $ItemBase, then
    if(regexmatches($ItemBase2, $ItemBase)) {
	
	  //Get the comment of $Item2
	  $cmt2 = tagitems("cmt", , "$Item2", 1);
	  
	  if($Item == $Item2) {status "Done!"; end '1==1';}   //If it is the same file, status "Done!" and exit
	  
	  //Comments
	  switch($cmt) {
	     case "":
	       if($cmt2 != "") {tagitems("cmt", "$cmt2", "$Item"); break;}
	       if($cmt2 == "") {$case = "2"; tagitems("cmt", "$Num", "$Item"); tagitems("cmt", "$Num", "$Item2"); break;}
		   break;
		 default:
		   if($cmt2 == "") {tagitems("cmt", "$cmt", "$Item2");}
		 }
    }
  }
}

Code: Select all

//Created : 2022-05-01
//Modified: 2022-07-22
//Function: Cut a segment of the filename of the list items for comparison, comments the same items with the same number
//Version : v2.1

//Enter the start and end positions of the crop
 $substrS = input("Enter starting position of the crop<crlf>For example 0, 5 or -10", , "0", 5:=300, 7:='0');
 $substrL = input("Enter the end position<crlf>For example 10, 25 or -2", , "300", 5:=300, 7:='350');
//Preview
 $curname = substr("<curname>", $substrS, $substrL);
 if $curname == "" {$curname = "No files is selected and cannot preview";}
 $confirm = confirm("Cropped filenames preview:<crlf><curname><crlf>$curname");
 if $confirm == "0" {end '1==1';}
 
 
 
//Get the current list items
 $List = report("{fullname}<crlf>", 0);
 $Num = "1";
 
 
 
//Each item of the list
 foreach($Item, $List, "<crlf>") {
//Get base filename and cut a segment
 $ItemBase = gpc($Item, "base");
 $ItemBase = substr("$ItemBase", $substrS, $substrL);
//Replace some regular elements
 $ItemBase = replacelist($ItemBase, " ", "");
 $ItemBase = replace($ItemBase, "|", "");
 $ItemBase = replacelist($ItemBase, "[|]|(|)", "", "|");
 $ItemBase = regexreplace($ItemBase, "[+]", "");
 
//Get the comment of $Item
 $cmt = tagitems("cmt", , "$Item", 1);
//Increments
 if($case == "2") {$Num++; $case = "";}
 
//Exclude computed files
 selectitems $Item;
 sel "+1";
 sel +, 100000;
 $List = report("{fullname}<crlf>", 1);
 
 
 
//Each item of the list(Exclude computed files)
    foreach($Item2, $List, "<crlf>") {
//Get base filename and cut a segment
    $ItemBase2 = gpc($Item2, "base");
	//$ItemBase2 = substr("$ItemBase2", $substrS, $substrL);
//Replace some regular elements
	$ItemBase2 = replacelist($ItemBase2, " ", "");
    $ItemBase2 = replace($ItemBase2, "|", "");
    $ItemBase2 = replacelist($ItemBase2, "[|]|(|)", "", "|");
    $ItemBase2 = regexreplace($ItemBase2, "[+]", "");
	
	
	
//If $ItemBase2 = $ItemBase, then
    if(regexmatches($ItemBase2, $ItemBase)) {
	
	  //Get the comment of $Item2
	  $cmt2 = tagitems("cmt", , "$Item2", 1);
	  
	  if($Item == $Item2) {status "Done!"; end '1==1';}   //If it is the same file, status "Done!" and exit
	  
	  //Comments
	  switch($cmt) {
	     case "":
	       if($cmt2 != "") {tagitems("cmt", "$cmt2", "$Item"); break;}
	       if($cmt2 == "") {$case = "2"; tagitems("cmt", "$Num", "$Item"); tagitems("cmt", "$Num", "$Item2"); break;}
		   break;
		 default:
		   if($cmt2 == "") {tagitems("cmt", "$cmt", "$Item2");}
		 }
    }
  }
}

Code: Select all

//Created : 2022-05-01
//Modified: 2022-07-20
//Function: Cut a segment of the filename of the list items for comparison, comments the same items with the increments number
//Version : v1.9 (Increments)

//Enter the start and end positions of the crop
 $substrS = input("Enter starting position of the crop<crlf>For example 0, 5 or -10", , "0", 5:=300, 7:='0');
 $substrL = input("Enter the end position<crlf>For example 10, 25 or -2", , "300", 5:=300, 7:='350');
//Preview
 $curname = substr("<curname>", $substrS, $substrL);
 if $curname == "" {$curname = "No files is selected and cannot preview";}
 $confirm = confirm("Cropped filenames preview:<crlf><curname><crlf>$curname");
 if $confirm == "0" {end '1==1';}
 
 
 
//Get the current list items
 $List = report("{fullname}<crlf>", 0);
 $Num = "0";
 
 
 
//Each item of the list
 foreach($Item, $List, "<crlf>") {
//Get base filename and cut a segment
 $ItemBase = gpc($Item, "base");
 $ItemBase = substr("$ItemBase", $substrS, $substrL);
//Replace some regular elements
 $ItemBase = replacelist($ItemBase, " ", "");
 $ItemBase = replace($ItemBase, "|", "");
 $ItemBase = replacelist($ItemBase, "[|]|(|)", "", "|");
 $ItemBase = regexreplace($ItemBase, "[+]", "");
 
//Get the comment of $Item
 $cmt = tagitems("cmt", , "$Item", 1);
 
//Exclude computed files
 selectitems $Item;
 sel "+1";
 sel +, 100000;
 $List = report("{fullname}<crlf>", 1);
 
 
 
//Each item of the list(Exclude computed files)
    foreach($Item2, $List, "<crlf>") {
//Get base filename and cut a segment
    $ItemBase2 = gpc($Item2, "base");
	$ItemBase2 = substr("$ItemBase2", $substrS, $substrL);
//Replace some regular elements
	$ItemBase2 = replacelist($ItemBase2, " ", "");
    $ItemBase2 = replace($ItemBase2, "|", "");
    $ItemBase2 = replacelist($ItemBase2, "[|]|(|)", "", "|");
    $ItemBase2 = regexreplace($ItemBase2, "[+]", "");
	
	
	
//If $ItemBase2 = $ItemBase, then
    if($ItemBase2 == $ItemBase) {
	
	  //Get the comment of $Item2
	  $cmt2 = tagitems("cmt", , "$Item2", 1);
	  
	  if($Item == $Item2) {status "Done!"; end '1==1';}   //If it is the same file, status "Done!" and exit
	  
	  //Comments
	  switch($cmt) {
	     case "":
	       if($cmt2 != "") {tagitems("cmt", "$cmt2", "$Item"); break;}
	       if($cmt2 == "") {$Num = $Num+1; tagitems("cmt", "$Num", "$Item"); tagitems("cmt", "$Num", "$Item2"); break;}
		 default:
		   if($cmt2 == "") {tagitems("cmt", "$cmt", "$Item2");}
		 }
    }
  }
}

Code: Select all

//Created : 2022-05-01
//Modified: 2022-05-24
//Function: Cut a segment of the filename of the list items for comparison, comments the same items with the same number
//Version : v1.8

//Enter the start and end positions of the crop
 $substrS = input("Enter starting position of the crop<crlf>For example 0, 5 or -10", , "0", 5:=300, 7:='0');
 $substrL = input("Enter the end position<crlf>For example 10, 25 or -2", , "300", 5:=300, 7:='350');
//Preview
 $curname = substr("<curname>", $substrS, $substrL);
 if $curname == "" {$curname = "No files is selected and cannot preview";}
 $confirm = confirm("Cropped filenames preview:<crlf><curname><crlf>$curname");
 if $confirm == "0" {end '1==1';}

//Get the current list items
 $List = listfolder(, , , <crlf>);
 $Num = "0";
//Each item of the list
 foreach($Item, $List, "<crlf>") {
//Get base filename and cut a segment
 $ItemBase = gpc($Item, "base");
 $ItemBase = substr("$ItemBase", $substrS, $substrL);
//Replace some regular elements
 $ItemBase = replacelist($ItemBase, " ", "");
 $ItemBase = replace($ItemBase, "|", "");
 $ItemBase = replacelist($ItemBase, "[|]|(|)", "", "|");
 $ItemBase = regexreplace($ItemBase, "[+]", "");
 
//Each item of the list
    foreach($Item2, $List, "<crlf>") {
//Get base filename and cut a segment
    $ItemBase2 = gpc($Item2, "base");
	$ItemBase2 = substr("$ItemBase2", $substrS, $substrL);
//Replace some regular elements
	$ItemBase2 = replacelist($ItemBase2, " ", "");
    $ItemBase2 = replace($ItemBase2, "|", "");
    $ItemBase2 = replacelist($ItemBase2, "[|]|(|)", "", "|");
    $ItemBase2 = regexreplace($ItemBase2, "[+]", "");
	
//Get the comment of $Item
 $cmt = tagitems("cmt", , "$Item", 1);
//Get the comment of $Item2
	$cmt2 = tagitems("cmt", , "$Item2", 1);
//If $ItemBase2 contains $ItemBase, and $Item != $Item2, then
    if(regexmatches("$ItemBase2", "$ItemBase") && $Item != $Item2) {
	if($cmt != "" && $cmt2 == "") {tagitems("cmt", "$cmt", "$Item2");}
	if($cmt == "" && $cmt2 != "") {tagitems("cmt", "$cmt2", "$Item");}
	if($cmt == "" && $cmt2 == "") {$Num = $Num+1; tagitems("cmt", "$Num", "$Item"); tagitems("cmt", "$Num", "$Item2");}
    }
  }
}
Win10, Win11 @100% 2560x1440 22H2

Post Reply