Page 1 of 1

Extract and rename extracted files

Posted: 20 May 2024 04:21
by kiwichick
I often download zip files containing images files that need to be renamed after extracting. I have two scripts. One that does the extracting and one that does the renaming. I'd like to combine them into the one process but I'm not having any luck. The issue I have is how to make sure the renaming portion of the script doesn't begin until the extraction has completed and the files appear in the list. I've tried using the Wait command but, because the amount of time it takes to extract depends upon how many files there are (and their combined size), it's not very successful. If I use too short a time, I get an error if the script tries to rename before extraction hasn't finished, or before the files appear in the list. If I use too long a time, there's unnecessary waiting for short extractions.

Here are my two scripts:

Code: Select all

end(getinfo("CountSelected") < 1), "Nothing selected!";
 zip_extract("", "",,,1);

Code: Select all

focus "L"; 
selectitems "*.png|*.jpg";

rename r, "(.+) - S(.+) > s$2";
rename s, " /";
rename r, "(.+) \[(.+)\].*$ > $1.jpg";
rename r, "(.+)\[(.+)\].*$ > $1.jpg";

$season = "season*";
$specials = "specials";
foreach($item, <get SelectedItemsNames>, <crlf>, "e") {
  $base = gpc($item, "base");
  $ext = gpc($item, "ext");
  if($base UnLikeI $season && $base UnLikeI $specials){
	RenameItem("poster.$ext", "$item");
	}
  if($base LikeI "season0"){
	RenameItem("specials.$ext", "$item");
	}
  }

Re: Extract and rename extracted files

Posted: 20 May 2024 05:08
by highend
Then don't do this with visible files but scan for them (the script doesn't continue anyway as long as the extraction isn't finished yet) (listfolder() / quicksearch()) and then do all renaming stuff on what's inside the variable instead of any selection first...

Re: Extract and rename extracted files

Posted: 20 May 2024 05:15
by kiwichick
highend wrote: 20 May 2024 05:08 Then don't do this with visible files but scan for them (the script doesn't continue anyway as long as the extraction isn't finished yet) (listfolder() / quicksearch()) and then do all renaming stuff on what's inside the variable instead of any selection first...
Thanks, highend, but I don't understand what you're suggesting.

Re: Extract and rename extracted files

Posted: 20 May 2024 05:18
by jupe
You probably just need a refreshlist; after the zip_extract though if you didn't want to rewrite the whole thing.

Re: Extract and rename extracted files

Posted: 20 May 2024 05:40
by kiwichick
jupe wrote: 20 May 2024 05:18 You probably just need a refreshlist; after the zip_extract though if you didn't want to rewrite the whole thing.
Thank you!! Perfect.