Rar.exe CLI - add files from directory without directory structure?

3

I need to grab every file in a folder and shove it into a RAR archive.

This is my current method:

"C:\Program Files\WinRAR\Rar.exe" a -r -md2m -s -m5 -ma4 -t ..\Releases\vCommands.rar bin\

... Where bin is my folder. I tried this too, even though it is for another program, and the results are the same.

To be clear, here's a picture:
difference

To the top-left, in the .rar file, there is the bin directory which contains all the files.
To the bottom-right, in the .7z file, all those files are in the archive root.

What I need is shoving all those files in the .rar archive root, instead of a folder, without having to execute my batch file inside that bin folder.

Vercas

Posted 2014-06-05T19:59:06.667

Reputation: 532

Answers

3

After reading the manual the 3rd time, I found the -ep switch.

-ep     Exclude paths from names. This switch enables files to be added
        to an archive without including the path information. This
        could, of course, result in multiple files existing in the
        archive with the same name.

I first misunderstood this because, as far as I know, path refers to directory and file name, thinking that it would strip the name completely from the files.
(this belief is due to my experience with other archive formats)

However, by path, the author meant directory.
A word of warning, it will strip all directory information (even from sub-directories), flattening the file structure.

Vercas

Posted 2014-06-05T19:59:06.667

Reputation: 532

0

Add rar.exe to the Path variable in Windows for ease of use.

Enter the directory you want to archive. TestDirectory in this case
\TestDirectory>rar a -m1 -vn -r ..\somber.rar
or
rar a -m1 -vn -r somber.rar

NesteaZen

Posted 2014-06-05T19:59:06.667

Reputation: 1

Polluting PATH on Windows is baaaad. :( – Vercas – 2017-06-09T04:23:33.763

0

I don't believe this is able to be done via command line switches.

What you would have to do is run a directory command and output the results to a text file. Then pull those results from the textfile via winrar and add them to the archive individually.

Use this to output the file list to a file dir /s /b >> filelist.txt

To zip them. "C:\Program Files\WinRAR\Rar.exe" a -r -md2m -s -m5 -ma4 -t ..\Releases\vCommands.rar @filelist.txt

I haven't tested this out but I believe this is the correct way to do it.

Travis

Posted 2014-06-05T19:59:06.667

Reputation: 1 044

Holy Lord, that creates every folder from the drive root up to the files in the archive. – Vercas – 2014-06-05T20:44:54.183