Function to recursivcely scan a folder and extract files to destination folder

With the existing default Extract button, if I select one or more folders that have .lha files in them, it will simply copy the contents of the folders into the current destination folder.

The default Archive Files/Extract to Destinaion Folders button, will create folders in the destination folder with the same folder names and copy the .lha files to them without extracting them - close but no cigar!

How can I make it not just copy the files, but extract them in the process?

I've tried making my own script to actually extract the each file, but it's not quite behaving.

If I select one of the souce folders, it creates a destination folder and extracts all the files from the source folder into it just fine.

If I select more than one folder from the source, it creates all the desitnation folders fine, but doesn't extract the files into their folders. The code is close, but still so cigar!

@runmode:hide
CREATEFOLDER {destpath}\{file} READAUTO=DUAL
GO {file}
SELECT ALL
"c:\program files (x86)\gnuwin32\bin\lha.exe" x {filepath} -w={destpath}\ 

I need it behave like the Archive Files/Extract to Destination Folders button, but extract the files too. If I open the folder first, and select all the .lha files, then it will create folders based on the filenames, I don't want it to do that.

The workaround of course is to manually create the destination folder, and then extract the files into that folder by selecting it first. Nice to be able to automate this process.

Thanks in advance!

You need to select the archives. The new folder names can be determined like this:

Copy EXTRACT CREATEFOLDER=newdestinationfolder