RAR a folder without persisting the full path
Asked Answered
H

3

8

1) I have a folder called CCBuilds containing couple of files in this path: E:\Testing\Builds\CCBuilds.

2) I have written C# code (Process.Start) to Rar this folder and save it in E:\Testing\Builds\CCBuilds.rar using the following command

"C:\program files\winrar\rar.exe a E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds"

3) The problem is that, though the rar file gets created properly, when I unrar the file to CCBuilds2 folder (both through code using rar.exe x command or using Extract in context menu), the unrared folder contains the full path, ie. extracting E:\Testing\Builds\CCBuilds.rar -> E:\Testing\Builds\CCBuilds2\Testing\Builds\CCBuilds\<<my files>>

Whereas I want it to be something like this: E:\Testing\Builds\CCBuilds2\CCBuilds\<<my files>>

How can I avoid this full path persistence while adding to rar / extracting back from it. Any help is appreciated.

Hardecanute answered 13/3, 2012 at 13:16 Comment(0)
G
27

Use the -ep1 switch.

More info:

-ep = Files are added to an archive without including the path information. Could result in multiple files existing in the archive with same name.

-ep1 = Do not store the path entered at the command line in archive. Exclude base folder from names.

-ep2 = Expand paths to full. Store full file paths (except drive letter and leading backslash) when archiving.

(source: http://www.qa.downappz.com/questions/winrar-command-line-to-add-files-with-relative-path-only.html)

Gorki answered 10/4, 2012 at 16:25 Comment(0)
P
1

Just in case this helps: I am currently working on an MS Access Database project (customer relations management for a small company), and one of the tasks there is to zip docx-files to be sent to customers, with a certain password encryption used.

In the VBA procedure that triggers the zip-packaging of the docx-files, I call WinRAR as follows:

c:\Programme\WinRAR\winrar.exe a -afzip -ep -pThisIsThePassword "OutputFullName" "InputFullName" 

-afzip says: "Create a zip file (as opposed to a rar file)

-ep says: Do not include the paths of the source file, i.e. put the file directly into the zip folder

A full list of such switches is available in the WinRAR Help, section "Command line".

Premedical answered 17/9, 2015 at 19:29 Comment(0)
I
0

x extracts it as E:\Testing\Builds\CCBuilds2\Testing\Builds\CCBuilds\, because you're using full path when declaring the source. Either use -ep1 or set the default working dir to E:\Testing\Builds.

Use of -ep1 is needed but it's a bit tricky.
If you use:

Winrar.exe a output.rar inputpath
Winrar.exe a E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds

it will include the input path declared:

E:\Testing\Builds\CCBuilds -> E:\Testing\Builds\CCBuilds.rar:
Testing\Builds\CCBuilds\file1
Testing\Builds\CCBuilds\file2
Testing\Builds\CCBuilds\folder1\file3
...

which will end up unpacked as you've mentioned:

E:\Testing\Builds\CCBuilds2\Testing\Builds\CCBuilds\

There are two ways of using -ep1.

If you want the simple path:

E:\Testing\Builds\CCBuilds\

to be extracted as:

E:\Testing\Builds\CCBuilds2\CCBuilds\file1
E:\Testing\Builds\CCBuilds2\CCBuilds\file2
E:\Testing\Builds\CCBuilds2\CCBuilds\path1\file3
...

use

Winrar.exe a -ep1 E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds

the files inside the archive will look like:

CCBuilds\file1
CCBuilds\file2
CCBuilds\folder1\file3
...

or you could use ep1 to just add the files and folder structure sans the base folder with the help of recursion and defining the base path as the inner path of the structure:

Winrar.exe a -ep1 -r E:\Testing\Builds\CCBuilds.rar E:\Testing\Builds\CCBuilds\*

The files:

E:\Testing\Builds\CCBuilds\file1
E:\Testing\Builds\CCBuilds\file2
E:\Testing\Builds\CCBuilds\folder1\file3
...

inside the archive will look like:

file1
file2
folder1\file3
...

when extracted will look like:

E:\Testing\Builds\CCBuilds2\file1
E:\Testing\Builds\CCBuilds2\file2
E:\Testing\Builds\CCBuilds2\folder1\file3
...

Anyway, these are two ways -ep1 can be used to exclude base path with or without the folder containing the files (the base folder / or base path).

Incorrigible answered 8/5, 2019 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.