6

I am trying to use WinRAR command line to zip folder:

"c:\Program Files\WinRAR\WinRAR.exe" a -afzip "e:\output.zip" "e:\foldertozip\"

If the foldertozip contains file, the command line works. But if the folder contain no file but folders where sub folder will contain files, it will appear the error saying No files to add.

How can I solve it?

user1995781
  • 489
  • 4
  • 8
  • 18

3 Answers3

9

If the folder contains no files apart from subfolder containing files there is an error

Use the -r recurse subfolders switch.


Examples to compress a folder

rar a -r yourfiles.rar *.txt c:\yourfolder

creates archive yourfiles.rar and compresses all .txt files in c:\yourfolder and all its subfolders

rar a yourfiles 

creates archive yourfiles.rar and compresses all files in the current folder, but doesn’t include subfolders (note lack of extension; WinRAR will use the default extension .rar)

  • a command adds to the archive

  • -r switch recurses subfolders

Source Using the WinRAR Command-line tools in Windows

DavidPostill
  • 153,128
  • 77
  • 353
  • 394
3

The problem is solved by removing \ at the back.

"c:\Program Files\WinRAR\WinRAR.exe" a -afzip "e:\output.zip" "e:\foldertozip"
user1995781
  • 489
  • 4
  • 8
  • 18
-1

you can use this: if the rar.exe file is in the program files folder c:\program files\winrar\rar a -r -df

docker
  • 1
  • 3
    Maybe be a bit more verbose and consider improving the formatting. What do those switches do? You could use ``` to mark something as differently. Right now it doesn't seem to be an improvement compared to the other answers? – Seth Dec 14 '16 at 08:06
  • Reportedly -df deletes files after archiving. See https://documentation.help/WinRAR/HELPSwitches.htm – Ray Woodcock May 29 '22 at 01:49