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:

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.


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.


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.

  • Holy Lord, that creates every folder from the drive root up to the files in the archive. – Vercas Jun 5 '14 at 20:44

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
rar a -m1 -vn -r somber.rar

  • Polluting PATH on Windows is baaaad. :( – Vercas Jun 9 '17 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.