Page 2 of 2

Re: Purging XY Thumbnails script

Posted: 04 Sep 2013 15:50
by klownboy
I made an update to the 2nd version (2nd post in this thread). It's the version that uses the actual thumbnail data files ".dat2" files to obtain the thumbnail data in lieu of the "xythumbs.txt" file. The main change is, it will you provide you the option of regenerating/recreating the xythumbs.txt file based on exactly what you have for thumbnail files after the thumbnail cleanup or it will simply update the xythumbs.txt. The option of recreating the xythumbs.txt is great especially if that file has been tampered with or has been recreated for some reason by XYplorer and would therefore not be complete or accurate. Remember that file is really not much more than a log of the changes made to the thumbnail data files. Like the update to the 1st version, it will also now will now pre-check any folders that do not exists in the inputselect box.

Code: Select all

      $thumbsmod = ""; $thumbssync = "";
      $dat2 = formatlist(folderreport("files", "r", "<xythumbs>", , , "<crlf>"), "f", "<crlf>", "*.dat2");
    if (confirm(quote("OK") . "  to recreate and sync your your XYthumbs.txt file with<crlf>the thumbnnail data files after thumbnail cleanup, or<crlf 2>" . quote("CANCEL") . " to update XYthumb.txt only after cleanup.")) {$sync = "1";}
  foreach($dat2file, $dat2, "<crlf>") {
       $filehash = getpathcomponent($dat2file, "base");      //gets the base file name which is the "hash"
       $dat2info = readfile("$dat2file", "b", 85, , 17);     //reads each thumbnail ".dat2" file for the folder and thumbnail size
       $thumbsfolder = gettoken($dat2info, 1, "*", "t");     //extract the folder
       $thumbssize = gettoken($dat2info, "2", "*", "t");     //extract the thumbnail size
       $filedate = property("#3", "$dat2file");              //obtains the file date
       if !(exists($thumbsfolder)) {                         //adds a pre-checked "+" for inputselect for folders that do not exists.
          $thumbsmod = $thumbsmod . "+" . $thumbsfolder . "|" . $thumbssize . "|" . $filedate . "|" . $filehash . "<crlf>";}
          else {$thumbsmod = $thumbsmod . $thumbsfolder . "|" . $thumbssize . "|" . $filedate . "|" . $filehash . "<crlf>";}
       if ($sync == "1") {     
          if !(exists($thumbsfolder)) {                      //adds a pre-checked "+" for inputselect for folders that do not exists.
          $thumbssync = $thumbssync . "+" . $thumbsfolder . "|" . $thumbssize . "|" . $filehash . "<crlf>";}
          else {$thumbssync = $thumbssync . $thumbsfolder . "|" . $thumbssize . "|" . $filehash . "<crlf>";}
         }
   }
     $thumbsmod = formatlist($thumbsmod, "se", "<crlf>");
     if ($sync == "1") {$thumbssync = formatlist($thumbssync, "se", "<crlf>");}
     else {$thumbstxt = readfile("<xythumbs>\XYthumbs.txt");}
  $sel_hash = inputselect("Select Thumbnails files to delete<crlf>based on folder location, thumbnail size and date.<crlf>Pre-checked folders no longer exist.", $thumbsmod, "<crlf>", 2, , 800, 800, "Thumbnail File Selection");
    foreach($hash, $sel_hash, "<crlf>")
    {
      $hash = gettoken($hash, -1, "|");           //pull-out the hash only portion of line
      delete 0, 0, "<xythumbs>\". $hash .".*";    //change 2nd parameter to "1" to prompt prior to deleting
     if ($sync == "1") {$thumbssync = regexreplace($thumbssync, ".*".$hash.".*$\r?\n?");}
      else {$thumbstxt = regexreplace($thumbstxt, ".*".$hash.".*$\r?\n?");}
     }
   if ($sync == "1") {   
     copytext "XYplorer Thumbs Index v1<br><date yyyy-mm-dd hh:mm:ss><br><br>";
     copytext $thumbssync, a ;
     $newThumbsTxt = "<clipboard>";
     writefile("<xythumbs>\XYthumbs.txt", $newThumbsTxt, "o", "tu");   //writes a new XYthumbs.txt file based on actual thumb data and cleanup
     status "XY thumbnail clean-up complete and XYthumb.txt regenerated and synced with thumbnail data files.";
     }
   else {
     writefile("<xythumbs>\XYthumbs.txt", $thumbstxt, "o", "tu");      //updates the XYthumbs.txt based on cleanup
     status "XY thumbnail clean-up complete and XYthumb.txt updated.";
     }
Please let me know if you have any issues.
Thanks,
Ken