The script attached has been very helpful in ridding my system of old unneeded thumbnails, mostly thumbs on flash drives or fixed drive folders in which I no longer need thumbnails or thumbnails in sizes that I no longer use. It will provide you with a list (obtained from XYthumbs.txt file) of the folders for which you have thumbsnails and their sizes and the date the thumbsfile was last modified. With that information, you can make a hopefully smart decision on which thumbnails you can, and probably should, get rid of in your XY thumbsnails folder. I had one computer that had over a gig and a half of thumbs in the thumbnails folder and 2 others that were well over a gig. I cut them in half and I still have quite a lot of photos/thumbs. See thread...http://www.xyplorer.com/xyfc/viewtopic.php?f=3&t=10048
At some point Don may incorporate built-in thumbnail maintenance in XY, but until then. I did this more as a learning experience than anything else. Thank you very much Marco for the regex. If you inadvertantly check off a folder which you wanted to keep the thumbnails and it gets deleted, it's not the end of the world anyway, just go to the folder and regenerate them. If you're not trusting initially, you can check it's operation first by going into some folders in which you wouldn't normally have thumbs generated, or to a folder which you have thumbs, but make them in a different size, and then use the script to delete them. Yes, you can pluck through your thumbnail folder and delete those thumbs by date and even look at the ".dat2" files to see the thumbnail folder and sizes, but this script should make slimming down the XY thumbnails folder much easier.
EDIT 1: Before trying this script, I'd recommend doing the full backup and I'd also save a copy of the XYthumbs.txt file separately right in the thumbnails folder. Save it as XYthumbs_orig.txt just in case. I wanted to point out that on one computer, the data which came back on the inputselect box was missing or not all there so to speak and it turns out it's due to the age old issues with Unicode vs Ansi. I think I might have messed with the XYthumbs.txt using good old Textpad and somehow screwed it up. I just ran it on a Windows 8 machine where I hadn't touched XYthumbs.txt in anyway and the script ran just fine. I may have to dump TextPad. It doesn't seem to be very good at maintaining code format. Unless I save "XYplorer.ini" in ANSI it never works and I have to get a backup.
EDIT 2: I updated the post to provide an indication in the inputselect box of those folders which no longer exists. These old folders will display with a check mark so if for some reason you don't want the associated thumbs deleted you'll have to uncheck the box. To test: (1) create a temp folder, and (2) copy some pictures into the folder, (3) make sure you view the pictures in a thumbnail view (try a couple different thumbnail sizes), (5) run the script (I call it "ThumbChaser.xys"), (6) you should see entries for each thumbsize that you made in the new folder, (7) select at least one thumb size/folder combination and execute the script, (8) view the "XYthumb.txt file" and confirm that the folder/thumbnail size was deleted, (9) now delete the temp folder you made and (10) run the script again (11) you should see lines pre-checked for each of the thumbsizes in that folder that you didn't delete previously.
Code: Select all
$thumbsmod = "";
$thumbstxt = readfile("<xythumbs>\XYthumbs.txt");
foreach($fileline, $thumbstxt, "<crlf>") {
if (gettoken($fileline, "count", "|") == "3") { //use only lines containing: folder|thumb size|hash
$thumbsfolder = gettoken($fileline, -3, "|"); //pull-out the thumb folder
$thumbssize = gettoken($fileline, -2, "|"); //pull-out thumb size
$filehash = gettoken($fileline, -1, "|"); //pull-out the hash
$filedate = property("#3", "<xythumbs>\$filehash.dat2"); //obtain filedate
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>";}
}
}
$thumbsmod = formatlist($thumbsmod, "se", "<crlf>");
$sel_hash = inputselect("Select Thumbnails files to delete<crlf>based on folder location, thumbnail size and date.", $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
$thumbstxt = regexreplace($thumbstxt, ".*".$hash.".*$\r?\n?");
}
writefile("<xythumbs>\XYthumbs.txt", $thumbstxt, "o", "tu");
status "XY thumbnail clean-up completed.";Ken
XYplorer Beta Club
