Archive: How to extract a .rar file and copy it to a diff. folder??


How to extract a .rar file and copy it to a diff. folder??
Hi,
I made a search and found that the nsExec command apparently can be used to extract .rar files together with Unrar, or so I understood.

I've been trying to use it in my installer to no avail. Mind you, I'm a 99% newbie, so that's normal, I guess.
Here's the basic script:

SetOutPath "$INSTDIR"
File "..\MediaAutoGraph.rar"
nsExec::unrar '"$INSTDIR\MediaAutoGraph.rar"'

I've been switching the " here and there, but I always get some sort of error. I just want to extract the .rar file (it will create a folder with a lot of files) and then I want to copy the extracted folder to a different location and overwrite an existing one.

any idea? thanks a lot...


nsExec can be used to run unrar.exe. It can't extract files from RAR archives on its own. Extract unrar.exe along with the RAR archive and use something like:

nsExec::ExecToLog '"C:\path\to\unrar.exe" "$INSTDIR\MediaAutoGraph.rar"'
unrar.exe might require some more information on the command line, so this example will probably not work as is.

Is there any other way to extract files on the fly from a rar archive?


7-zip's command line utility might be able to extract RAR archives as well.


Ok, I tried your command line and extracting also UnRAR.exe together with the rar archive. Obviously, UnRAR needs some extra parameters to extract the archive.

This is what i get in the log window:

Extract: UnRAR.exe... 100%
Extract: MediaAutoGraph.rar... 100%

UNRAR 3.51 freeware Copyright (c) 1993-2005 Alexander Roshal

Usage: unrar <command> -<switch 1> -<switch N> <archive> <files...>
<@listfiles...> <path_to_extract\>

<Commands>
e Extract files to current directory
l[t,b] List archive [technical, bare]
p Print file to stdout
t Test archive files
v[t,b] Verbosely list archive [technical,bare]
x Extract files with full path

<Switches>
- Stop switches scanning
ac Clear Archive attribute after compression or extraction
ad Append archive name to destination path
ap<path> Set path inside archive
av- Disable authenticity verification check
c- Disable comments show
cfg- Disable read configuration
cl Convert names to lower case
cu Convert names to upper case
dh Open shared files
ep Exclude paths from names
ep3 Expand paths to full including the drive letter
f Freshen files
id[c,d,p,q] Disable messages
ierr Send all messages to stderr
inul Disable all messages
ioff Turn PC off after completing an operation
kb Keep broken extracted files
n<file> Include only specified file
n@ Read file names to include from stdin
n@<list> Include files in specified list file
o+ Overwrite existing files
o- Do not overwrite existing files
oc Set NTFS Compressed attribute
ow Save or restore file owner and group
p[password] Set password
p- Do not query password
r Recurse subdirectories
ri<P>[:<S>] Set priority (0-default,1-min..15-max) and sleep time in ms
ta<date> Process files modified after <date> in YYYYMMDDHHMMSS format
tb<date> Process files modified before <date> in YYYYMMDDHHMMSS format
tn<time> Process files newer than <time>
to<time> Process files older than <time>
ts<m,c,a>[N] Save or restore file time (modification, creation, access)
u Update files
v List all volumes
ver[n] File version control
vp Pause before each volume
x<file> Exclude specified file
x@ Read file names to exclude from stdin
x@<list> Exclude files in specified list file
y Assume Yes on all queries


I tried this, but no luck:

File "..\UnRAR.exe"
File "..\MediaAutoGraph.rar"
nsExec::ExecToLog '"$INSTDIR\UnRAR.exe e" "MediaAutoGraph.rar"'

also tried using 7z:
File "..\7z.exe"
File "..\MediaAutoGraph.rar"
nsExec::ExecToLog '"$INSTDIR\7z.exe e" "MediaAutoGraph.rar"'


Get the 'e' out of the quotes. The first quotes should surround just the path to the executable.


code:


also tried using 7z:
File "..\7z.exe"
File "..\MediaAutoGraph.rar"
nsExec::ExecToLog '"$INSTDIR\7z.exe" e MediaAutoGraph.rar'


thanks guys, got it working:

nsExec::ExecToLog '"$INSTDIR\7z.exe" e MediaAutoGraph.rar -oc:\downloads\test"'

it copies the content of the rar archive to the downloads\test folder.


I think you've got one to many quotes there.
nsExec::ExecToLog '"$INSTDIR\7z.exe" e MediaAutoGraph.rar -o"c:\downloads\test"'

-Stu


it'w weird, beucause it does work this way:
nsExec::ExecToLog '"$INSTDIR\7z.exe" e MediaAutoGraph.rar -aoa -oc:\downloads\test"' [aoa command overwrites without asking first]

i'll try your way now...

well, well, well, it works both ways.
nsExec::ExecToLog '"$INSTDIR\7z.exe" e MediaAutoGraph.rar -aoa -oc:\downloads\test"'

and

nsExec::ExecToLog '"$INSTDIR\7z.exe" e MediaAutoGraph.rar -aoa -o"c:\downloads\test"'

it seems that the right way should be the second one, but the first one also works. weird, huh?


It's probably worth pointing out at this point that 7z.exe will only work if 7zip is installed. If you just ship 7z.exe and the target system has not got 7zip installed, it won't be able to extract anything.

There is a standalone .exe provided by 7zip called 7za.exe, but unfortunately that does not extract from rar files. I'm trying to be able to extract rar's, zip's and 7z's in my installer, and the only solution I have found so far is to ship both 7za.exe and unrar.exe, for a whopping total of 686k.

If anyone knows of a more lightweight solution with zip, 7z, and rar capability, I'd love to hear of it.


BTW, why to use NSIS to extract a temporary archive file like a RAR or ZIP (and it's uncompressor utility) and then extract final files from the archive?

NSIS can drop final files just like an archiver. You only need to uncompress your files locally and add them (or the directory containing them) to your NSI script, then compile.

File /r and it's other options are enougth. I can't think about a situation where a simple archiver is required as an intermediate step.

At least for me, NSIS's solid lzma compress a lot more than WinRAR with the maximum compression option.

++Vitoco


Originally posted by vitoco
BTW, why to use NSIS to extract a temporary archive file like a RAR or ZIP (and it's uncompressor utility) and then extract final files from the archive?
We dont speak of something like this:
File archive.rar
Unpack archive.rar

We speak about using installer to unpack an archive which already exists (on same CD maybe).
What is more - NSIS have it's limitations - it's 2GB per file. If you want to distribute some more, u need to pack data into separate archives.

Please don't reply to a discussion that's been closed for five(!) years.