Cache all thumbnails for current tab and sub folders at once

Discuss and share scripts and script files...
nf_xp
Posts: 35
Joined: 10 Jul 2009 08:05

Cache all thumbnails for current tab and sub folders at once

Post by nf_xp »

Cache all thumbnails for current tab and sub folders at once.
NOTE: Using this script on a very large folder may take a long time.

Code: Select all

"Cache Thumbnails"
	setting AllowRecursion;
	$curDir = <curpath>;
	#302; // Details
	#308; // Thumbnails #3
	sub "_cache_dirs";
	goto $curDir;

"-"

"Empty Cache"
	getkey $cacheDir, "CacheDir", "Thumbs";
	substr $c, $cacheDir, -1;
	if ($c != "\") { $cacheDir = $cacheDir . "\"; }
	delete 0, 0, $cacheDir . "*";

"_cache_dirs"
	sub "_cache_dir";
	sel f;
	sel i;
	$dirs = getinfo("SelectedItemsPathNames", "|");
	$n = getinfo("CountSelected");
	$i = 1;
	while ($i <= $n) {
		$dir = gettoken($dirs, $i, "|");
		goto $dir;
		sub "_cache_dirs";
		$i++;
	}

"_cache_dir"
	focus;
	sel 1;
	#485; // Refresh File List
	$lastFocused = 0;
	$focused = getinfo("FocusedPos");
	while ($focused != $lastFocused) {
		sendkeys "{PGDN}", 1;
		#485; // Refresh File List
		$lastFocused = $focused;
		$focused = getinfo("FocusedPos");
	}
Attachments
Thumbnails.xys
(860 Bytes) Downloaded 443 times

admin
Site Admin
Posts: 60558
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Cache all thumbnails for current tab and sub folders at once

Post by admin »

It nicely recurses the folder tree, but the {PGDN} somehow does not seem to work. It only produces thumbs of the top page of each folder. No time to investigate further though. I assume it works as expected at your end.

BTW, "create/cache all thumbnails in current folder now" is a planned function for one of the next versions.

nf_xp
Posts: 35
Joined: 10 Jul 2009 08:05

Re: Cache all thumbnails for current tab and sub folders at once

Post by nf_xp »

admin wrote:It nicely recurses the folder tree, but the {PGDN} somehow does not seem to work. It only produces thumbs of the top page of each folder. No time to investigate further though. I assume it works as expected at your end.
Weird, it should work as you're pressing {PGDN} via the keyboard, unless the file list wasn't focused. Is it some apps take over the focus during the generating of (non-picture) thumbnails in your box?
A bug? -> {PGDN} also doesn't work if the file list area is too narrow that contains less than two thumbnail rows. It should work anyway like you are clicking the below of the scroll thumb.
admin wrote:BTW, "create/cache all thumbnails in current folder now" is a planned function for one of the next versions.
Nice feature! I was about to post this wish :D
Please make it also an option not only a command, so we don't have to click a toolbar button or press a key for each of hundreds of folders.

admin
Site Admin
Posts: 60558
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Cache all thumbnails for current tab and sub folders at once

Post by admin »

As sendkeys officially does not even exist I won't take the time to look into it. :P

nf_xp
Posts: 35
Joined: 10 Jul 2009 08:05

Re: Cache all thumbnails for current tab and sub folders at once

Post by nf_xp »

admin wrote:As sendkeys officially does not even exist I won't take the time to look into it. :P
Sure thing, it's even not a real bug. :)

tryforsure
Posts: 23
Joined: 29 Jun 2009 13:56

Re: Cache all thumbnails for current tab and sub folders at once

Post by tryforsure »

This is an great script, thanks.

Stef123

Re: Cache all thumbnails for current tab and sub folders at

Post by Stef123 »

I run into various problems with this script:
In some folders it hangs up, going into a kind of loop, screen flickering, ESC brings up an abort-message, again and again, have to shoot XY down via task manager.

More often than not, I can remedy the situation above by first clearing out the cache, then have XY create some thumbs, then (and only then) running the script - and it works fine on the very same folders where it got stuck before.

Selecting the option "Empty Cache" leads to an XY error message telling me
'getkey' is not a valid script command
'substr' is not a valid script command

Can someone please help me out or bring this script up to par with XY 14.30.0100?

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Cache all thumbnails for current tab and sub folders at

Post by PeterH »

Oh - rather old script! Part of the syntax isn't valid any more.

Especially the statements you mentioned: they have changed from commands to functions, looong long ago!

Code: Select all

   getkey $cacheDir, "CacheDir", "Thumbs"; // old = invalid
   $cacheDir = getkey("CacheDir", "Thumbs"); // "new"

   substr $c, $cacheDir, -1; // old = invalid
   $c = substr($cacheDir, -1); // "new"
(Excuse: too lazy to check exact syntax - but I think it should be OK :roll: )
Win11 Pro 223H2 Gerrman

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Cache all thumbnails for current tab and sub folders at

Post by klownboy »

Yes, I had the same issues when I tested it last night. In defense of nf_xp, this script is quite old. The command for "Refresh thumbnails", Command ID #501 (or #506) was not in existence at that time. As I mentioned in the other thread I think I'll update my thumbnail cleanup script and include options to generate new thumbs for a folder via refresh, but I'll use the thumbnail database to select the folders as oppose to using the current folder as was done in this script.

And I see PeterH has mentioned as I was typing, the issues with the old command vs functions.
Ken
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

Stef123

Re: Cache all thumbnails for current tab and sub folders at

Post by Stef123 »

@ PeterH
Thanks for checking into this. After replacing those lines "Empty Cache" no longer causes any error messages. But it doesn't clear the cache, either.
"Cache Thumbnails" still gets stuck in some folders. If I don't stop the screen flickering by holding down ESC, it will crash XY after 20 seconds.
Maybe this script is just too old to be rescued.
klownboy wrote:... I'll update my thumbnail cleanup script and include options to generate new thumbs for a folder via refresh, but I'll use the thumbnail database to select the folders as oppose to using the current folder as was done in this script.
Much appreciated. This would essentially provide the missing feature of optimizing the cache. Great.

Is there a way to add an entire folder (including all subfolders) to the cache - without having to go into each and every branch and wait for XY to do it? In some folders this takes several minutes ("super-fast" setting = ON).

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Cache all thumbnails for current tab and sub folders at

Post by klownboy »

Hi Stef123, I'm done with the new version of my old script that was here Purging Thumbnails. I'm running it through some test, making temp folders placing photos in it, deleting photos, and refreshing etc to ensure the refresh is working properly. I'll post it later today - probably in a new script thread since my last version was listed under Tips & Tricks...

As I mentioned before, it will have a inputselect dialog box displayed which will allow you to do as that existing script did: delete non-existing, old thumbnail cache file(s), thumbs in sizes not desired, or thumb caches you simply no longer need. It will also have an inputselect to do a refresh on any existing thumbnail caches simply by checking off the boxes and letting it go to town. I don't think it will matter what your quality setting are, but to work properly it will need the Configuration setting for "Create all at once" to be set/checked. The script will do that if you don't already. I never had it checked myself previously and I probably should have. Having it checked will ensure they are all refreshed withough having to scroll the next page of thumbs into view and it's needed for the script to ensure all the individual folder thumbs are refreshed before moving onto to subsequent folders. It has no affect once the thumbs are generated so it make sense to have it on.
Ken
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

Stef123

Re: Cache all thumbnails for current tab and sub folders at

Post by Stef123 »

Thank you Ken,

I really appreciate this. "Create all at once" is always ON in my settings - no problem here.

Concerning the script of this thread - Cache current tab + subfolders - I think I narrowed down the hang-ups and screen flickering to the 4th line of the script

Code: Select all

#302; // Details
When I delete this line it seems to run OK. Any ideas? Just trying to understand to improve my scripting skills. :oops:

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Cache all thumbnails for current tab and sub folders at

Post by PeterH »

Stef123 wrote:Thank you Ken,

I really appreciate this. "Create all at once" is always ON in my settings - no problem here.

Concerning the script of this thread - Cache current tab + subfolders - I think I narrowed down the hang-ups and screen flickering to the 4th line of the script

Code: Select all

#302; // Details
When I delete this line it seems to run OK. Any ideas? Just trying to understand to improve my scripting skills. :oops:
If I see it right, the sequence of
#302; // Details
#308; // Thumbnails #3
seems a bit strange: set view to Details, then immediately set it to Thumbnails #3.
No wonder if it flickers. And what might be the reason for first setting Details View :?:

So deleting #302 might really make sense...

(That's not about scripting skills - it's about "what might the programmer have thought?")
Win11 Pro 223H2 Gerrman

Stef123

Re: Cache all thumbnails for current tab and sub folders at

Post by Stef123 »

PeterH wrote: No wonder if it flickers. And what might be the reason for first setting Details View :?:

So deleting #302 might really make sense...
Thank you, Peter. Reassures me to feel less troubled by deleting this line.
For some strange reason the original script - with this line in place - works fine for some folders, but gets stuck in others. I suspect it may have to do with folder views or the toggle-function of #302; - when I run it repeatedly via the AB, it switches my view back and forth between thumbs and details.

My other guess - it may have to do with this line towards the end

Code: Select all

sendkeys "{PGDN}", 1;
If I press PageDown repeatedly it will reach the bottom file - ONLY in details view, though. So the only adverse effect - as far as I can tell - would be an incomplete rendering of thumbs if I delete this line. I hope there is no other downside I may have overlooked.

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Cache all thumbnails for current tab and sub folders at

Post by klownboy »

From my experience using sendkeys in XY scripts can be finicky. I suppose that's why it's undocumented. I tend to use AHK quite a bit to do things in XY that I can't do with XY scripting alone. Don had mentioned issues associated with {PgDn} in a previous post in this thread. When you have "Create all thumbs at once" selected you don't need to page down. Of course that option and Refresh Thumbnails (#501) wasn't available when the script was written. I noticed the #302 followed by #304 a couple of days ago and just scratched my head.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

Post Reply