Button to convert ZIP/RAR to LHA

I have the following function to convert ZIP/RAR files to LHA format. It works just fine if I select just one file from the source lister, but if I select multiple files it creates a single LHA file with all the selected ZIP files. I need it to create individual files for each selected ZIP/RAR. What am I missing?

COPY EXTRACT CREATEFOLDER c:\lha
CD c:\lha
"c:\program files (x86)\gnuwin32\bin\lha.exe" a {file|noext}.lha *.*
COPY MOVE c:\lha\{file|noext}.lha to {rightpath} WHENEXISTS REPLACE
DELETE QUIET c:\lha

When multiple files are selected, each line that uses a single-file code like {file} will be run once for each file, before anything for the next line is run.

If you need to run all of the lines for file 1 before running anything for file 2, you'd need to switch to scripting for that. Scripting gives you full control over which line(s) run on which files and when they run.

Given that Opus already recognises ZIP and RAR files, is there a way to integrate the LHA.exe as so that it appears as another archive type to the existing list?

Using a folder like c:\lha\{file|noext} instead of c:\lha might work.

Actually, I was on that idea already! And it's very close!

Instead of doing one zip at a time, I can batch unzip each one into their own folder. That way when LHA runs on each file, it can create a new LHA file for each folder... so far so good.

For some reason though, it only COPY MOVE's the first file in the list and rest remain the C:\LHA folder. That is weird as it's supposed to repeat the COPY MOVE function for each file.

COPY EXTRACT CREATEFOLDER c:\lha\{file|noext}
@runonce cd c:\lha
"c:\program files (x86)\gnuwin32\bin\lha.exe" a {file|noext}.lha c:\lha\{file|noext}\*.* -q
COPY MOVE c:\lha\{file|noext}.lha to {rightpath} WHENEXISTS REPLACE

Ok, I got it working now... without having to use scripting. There is a small issue but I can live with it (unless there is a solution for that too), and that is the resulting LHA file has the parent directory name first then the files within that when you open it. ie.
example.lha
.example/folder
.example/file1.abc
.example/file2.abc
etc

I would have prefered:
example.lha
.folder
.file1.abc
.file2.abc
etc

I know it's because that since each line of the code is run as a batch for each zip file (as per the previous advice), LHA.exe adds that full path name because I'm executing outside of that folder so it adds it in, if you know what I mean. If it could be run within the folder, then only the files within that folder would be added and not the parent folder too.

Oh, and also it would be nicer if a DOS window didn't pop up each time either, but not sure how to suppress that.

COPY EXTRACT CREATEFOLDER c:\lha\{file|noext}
@runonce CD c:\lha
@runonce c:
"c:\program files (x86)\gnuwin32\bin\lha.exe" -a {destpath}\{file|noext}.lha {file|noext} -q
@runonce DELETE QUIET c:\lha
@runonce {sourcepath}

You probably don't need any of the @runmode modifiers, since none of those lines should run more than once anyway.

The c: line also shouldn't be needed.

LHA.exe is creating the archive so it'd depend on how it works, which I'm not familiar with. It might have an option to prevent that, or you might be able to specify {filepath}* which would give you all the files inside the folder, if it supports wildcards. (That would also remove the need to change directories at all, since everything would be full paths.)

You can use @runmode:hide on a line by itself to prevent that.

Ok great, I got it to work but still with that extra folder name, no big deal. I think it's just a limitation of LHA. I can't see any parameters to not include that parent folder name.

Here's the working final version:

1 Like