Compare selected files

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

Compare selected files

Post by Norn »

Compare selected files:

Code: Select all

//Function : Compare selected files
//Created  : 2022-07-08
//Modified : 2022-07-11
//Version  : 1.3



 //Set hash type (md5, sha1, sha256. . .)
 $hashType = "md5";
 
 
 
 //Get selected items
 $items = get("selecteditemspathnames");

 $itemsHashes = ""; 
 $exclude = "";
 $equalItemsList = "";
 $exclude2 = "";
 
 //Get the hashes (md5, sha1, sha256. . .) of the selected files
 foreach($item0, $items, "<crlf>", "e") {
	$hash0 = hash($hashType, $item0, 1);                            //Get the hash (md5, sha1, sha256. . .) of each file
	$itemsHashes .= "$item0" . "<crlf>" . "$hash0". "<crlf><crlf>"; //Stack files and hashes
	}
 
 
 
 //Foreach $itemsHashes
 foreach($item, $itemsHashes, "<crlf><crlf>", "e") {
    $hash = gettoken($item, 2, "<crlf>");                           //Get the hash (md5, sha1, sha256. . .) in $item
	
	$case = "";
	$equal = "";
	
	//Foreach $itemsHashes
    foreach($item2, $itemsHashes, "<crlf><crlf>", "e") {
	   
	   if($item != $item2) {                                        //Exclude the same file
         $hash2 = gettoken($item2, 2, "<crlf>");                    //Get the hash (md5, sha1, sha256. . .) in $item2
	     if($hash == $hash2) {                                      //Compare
		   $exclude .= "$item2" . "<crlf><crlf>";                   //Stack the list of exclusions
		   $equal .= "$item2" . "<crlf>";                           //Stack files with the same hashes
		   }
	     }
	   }
	   
	   
	   
	foreach($item3, $exclude2, "<crlf><crlf>", "e") {
	   if($item == $item3) {$case = "1";}                           //Exclude file $item that have been compared
	   }
	
	
	
	//if $equal is not epmty and $item is not in the exclusion list
	if($equal != "" && $case != "1") {
	  //Stack $item(filepath and hash) and $equal(filepath and hash), all files with the same hashes
	  $equalItemsList .= "$item" . "<crlf>" . "$equal" . "<crlf><crlf>";
	  //Stack $item and $exclude as an exclusion list
	  $exclude2 .= "$item" . "<crlf><crlf>" . "$exclude";
 }

}


 //Show results
 if($equalItemsList != "") {
   echo "Files Hashes comparison Results:<crlf><crlf>$equalItemsList";
   text "Files Hashes comparison Results:<crlf><crlf>$equalItemsList";
   
   //Select items
   selectitems $exclude2;
   end '1==1';
   }

 msg "No items with the same hashes";
Win10, Win11 @100% 2560x1440 22H2

Post Reply