Delete archive ONLY if no error

Hi,
After extracting an archive I want to be able to delete it (the original) ONLY if no error occurs (i.e wrong password).

example:

"C:\Program Files\WinRAR\WinRAR.exe" x {f} {d} 
Delete {f} ALL FORCE QUIET

this extract and deletes the archive regardless of the errorlevel.

I want to be able to delete the archive only if no error occurs.
Is there a way to accomplish something like this:

"C:\Program Files\WinRAR\WinRAR.exe" x {f} {d} 
if ERRORLEVEL 1 exit else goto Delete
:Delete
Delete {f} ALL FORCE QUIET

Off course I could enable this functionality inside WinRAR itself, but there are some scenarios when I want to keep the original file. Opening WinRaR each time to change that can be frustrating.
I went through Opus, WinRaR and 7-Zip documentation but none offer me a way to do it with commandline.

Using DOS batch-file branching in combination with Opus commands won't work since the Opus commands are run separately (and the batch file split up between internal commands).

You should either use the DOS del command, instead of the Opus delete command, or use the dopusrt.exe program to run the Opus delete command as part of the batch file.

Something like this (NOT TESTED):

"C:\Program Files\WinRAR\WinRAR.exe" x {f} {d}
if ERRORLEVEL 1 exit else goto Delete
:Delete
del {f}

Or this (also NOT TESTED):

"C:\Program Files\WinRAR\WinRAR.exe" x {f} {d}
if ERRORLEVEL 1 exit else goto Delete
:Delete
"C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe" /CMD Delete {f} ALL FORCE QUIET

You may also be able to do it using just internal commands and extracting the files using Opus instead of WinRAR.

DOH!
doesn't see the wood for the trees

anyway, thx leo. both methods (of course) work fine

I see posts about problems with Rar alot here. If you are having problems, I would suggest installing ExtractNow http://www.extractnow.com/, or UnZiplify http://www.silverbandsoftware.com/tabdown/unziplify/. These programs are small, extract multiple formats, and allow you to set automatic options for extraction and post extraction (search for archives in folders and subfolders, enque, extract here, extract new folder, delete archive when no errors, etc.). You can then add these to your context menu using the folowing

Program_GUID
Standard Function
FileType CONTEXTMENU {GUID of Program} CONTEXTFORCE

They make my life a lot easier when messing with a bunch of archives!

HookEm!!

hm ok, when extracting multiple archives the script doesn't do it's magic as intended. The deletion only occurs when ALL extractions report an errorcode of 0. If one is erroneous none of the archives is deleted, even if the others are successful.

clues?

@UTChamps05: well thx for the recommendation, but seems it won't help in this situation. Like WinRaR, you can set the option to delete only within the settings, no batch.

Of course I could use any of the two Apps for the deletion part and another or dopus internal for extraction only. that would be the last resort.

If rar.exe had a delete switch everything would be smooth.

If anyone is wondering how I'm implementing this:

You could move the commands into a batch file (or an Opus "user command" for that matter) and then make the main button call that, once per file, passing the paths as arguments.

With a separate batch being run for each file you'll get independent error/delete logic for each file as well.

another DOH! thx again.

PS: are you getting paid by gpsoft for your support here, leo? I mean your support here is legendary. deserves appreciation, absolutely.

Opus is payment enough! :slight_smile:

In my opus this code don't work

COPY EXTRACT HERE
if ERRORLEVEL 1 exit else goto Delete
:Delete
del {f} ALL FORCE QUIET

"Windows cannot find 'if'..."

The "If" command is only available with MS-DOS Batch Type buttons.

However, even if you change the button type that code still won't work. The MS-DOS ERRORLEVEL variable is only set by other DOS commands and won't be set by the internal Opus Copy command.

If you want to use "if ERRORLEVEL..." then you have to use an external command such as WinRar.exe or 7zG.exe to do the extraction.

Ok thanks for explanation