I want to write an extractor app to extract a lot of archived files (*.tgz and *.rar) using C#.
I can't find any universal component which support all of this archived file formats. For this reason, I'm trying to use WinRAR.exe
. But in this case I have some problems. For example: I want to know if an archive did not extract successfully. And get error message and file name for review, but I cannot handle WinRAR errors in C#.
Any idea to handle WinRAR error? Or is there any universal component to extract archive files?
Console version Rar.exe
cannot be used here as it supports only RAR archives. Extraction from ZIP, TAR and other archive formats is supported only by WinRAR.exe
.
Open help of WinRAR - file WinRAR.chm
in program files folder of WinRAR. Select tab Contents and open Command line mode and WinRAR exit codes and click on List of WinRAR exit codes. This list contains the values returned to the calling application which is here your application. As you can read any value greater 0 means there was a problem.
Next help of WinRAR contains also below Command line mode the list item Switches. There are several switches which are of interest for your task. Best look first on help page Alphabetic switches list.
You should call WinRAR.exe always with the switch -cfg-
to avoid depending on user configuration.
The -ilog
switch is the next one to use to get all error message written into a file which can be read after WinRAR finished.
But I do not really understand why somebody should use your application for extracting archives as there are already several shareware and freeware tools available. Also WinRAR is shareware. So the users of your application would need to buy a license for WinRAR.
Only unrar.dll as used by many other applications for extracting RAR archives is freeware as also console application UnRAR.exe. But with UnRAR.exe and unrar.dll it is only possible to extract RAR archives. Creating RAR archives or extracting archives of other formats are not supported by UnRAR.exe and unrar.dll.