script: refresh missing thumbnails in current and all sub folders

Discuss and share scripts and script files...
Post Reply
jleeca
Posts: 19
Joined: 17 Feb 2017 05:17

script: refresh missing thumbnails in current and all sub folders

Post by jleeca »

Hello everyone,

I'm sharing the following script which can be used to refresh all thumbnails in a current folder and all-subfolders. I hope this script will be helpful for you.

Code: Select all

"Create missing thumbnails (current and subfolders)";
  $cur_folder = "<curpath>";
  $subDirs = folderreport("dirs", r, $cur_folder, r);
  foreach ($sub, $subDirs, <crlf>){
    goto "$sub";
    #507;
    while(1) {
      if (strlen(regexmatches(get("status", 3), " refreshed")) != 0) {
        break;
      }
      wait 10;
    }
  }
  goto "$cur_folder";

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

Re: script: refresh missing thumbnails in current and all sub folders

Post by klownboy »

Hi jleeca, nice script. I take it you must have in your Configuration "Show cached thumbnails only" checked and possibly "Create all thumbnails at once" unchecked? My settings are just the opposite.

- After applying settings I assumed were yours, I ran your script in a folder with subs that I populated with new images (some were cached some not). I ran into problems with the script going into a endless loop if there are no thumbs to refresh. I believe because it's looking to find " refreshed" in the status bar. That's fine if you know every folder is going to have uncached thumbs, but what if they don't?
- Also folder report doesn't include the current folder. Consequently, the foreach loop will not include the current folder. So, you have to add it to the list of folders before the foreach.
- Unless I'm missing something, why not eliminate the while loop and simply wait until the refresh is accomplished and then move on to the next folder.
The following seemed to work fine for me. Let me know if it works or doesn't work for you.

Code: Select all

"Create missing thumbnails (current and subfolders)";
 //checks if a folder is highlighted in list <curitem> if not use <curpath>
  if(exists(<curitem>) == 2) {$cur_folder = <curitem>;} else {$cur_folder = <curpath>;} 
  if(substr($cur_folder, -1) != "\") {$cur_folder = $cur_folder . "\";} //adds a final backslash if not already
  $paths = "$cur_folder" . "<crlf>" . (folderreport("dirs", "r", $cur_folder, "r", , "<crlf>"));
  foreach ($path, $paths, <crlf>, "e"){
     if(substr($path, -1) != "\") {$path = $path . "\";}
     goto "$path";
     #507;wait 10;
  }
  goto "$cur_folder";
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

jleeca
Posts: 19
Joined: 17 Feb 2017 05:17

Re: script: refresh missing thumbnails in current and all sub folders

Post by jleeca »

klownboy wrote:I take it you must have in your Configuration "Show cached thumbnails only" checked and possibly "Create all thumbnails at once" unchecked?
Correct. That's the configurations that I must use to avoid the delay when opening the directory because I have lots of files in many folders.
klownboy wrote:- After applying settings I assumed were yours, I ran your script in a folder with subs that I populated with new images (some were cached some not). I ran into problems with the script going into a endless loop if there are no thumbs to refresh. I believe because it's looking to find " refreshed" in the status bar. That's fine if you know every folder is going to have uncached thumbs, but what if they don't?
If there's no thumbs to refresh, then "0 thumbs refreshed" message appears in the status bar so the script still works for me. Besides, "wait 10" is just a delay checking the status. It alone doesn't work because #507 action will just get canceled if script doesn't wait it's completion by its own.
klownboy wrote:- Also folder report doesn't include the current folder. Consequently, the foreach loop will not include the current folder. So, you have to add it to the list of folders before the foreach.
I didn't bother to update the script after finding the problem you described. The following is the latest script that I currently use. Please the updated script aborts if a tab is switched because I found the program crashes if switch the tab while the script is running.

Code: Select all

"Create missing thumbnails (current and subfolders)";
  $cur_folder = "<curpath>";
  $cur_tabid = tab("get", "ID"); 
  $subDirs = folderreport("dirs", r, $cur_folder, r);
  foreach ($sub, $subDirs, <crlf>){
    end tab("get", "ID") != $cur_tabid, "Script canceled"; 
    goto "$sub";
    end tab("get", "ID") != $cur_tabid, "Script canceled"; 
    #507;
    end tab("get", "ID") != $cur_tabid, "Script canceled"; 
    while(1) {
      if (strlen(regexmatches(get("status", 3), " refreshed")) != 0) {
        break;
      }
      wait 10;
    }
  }
  goto "$cur_folder";
  #507;

Post Reply