RAR a folder without persisting the full path

Ramya picture Ramya · Mar 13, 2012 · Viewed 19.1k times · Source

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.

Answer

guidod picture guidod · Apr 10, 2012

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)