10
 7za a -t7z -mmt -mx9 -y Include.7z .\Include\*

The above command adds the files to the 7z archive, but what if I want them in a custom subfolder?

For example Files\ inside .7z

2
  • Check the help and look through options: -o {OutputDir}
    – Przemek M
    Oct 16, 2015 at 23:58
  • -o is for specifying an output folder when extracting, not a folder to add files to in an archive.
    – Jonas
    Feb 25, 2021 at 11:10

3 Answers 3

5

It appears that the developer himself has answered this question when you asked him:

Now there is no option for that task.

You can use additional "rn" (Rename) command to rename folder inside archive.

By experimenting, I found that alternatively, you can create the folder structure that you want to be added. Let your "staging area" refer to the place on your filesystem where you prepare the files/folders to be added... For your example, you could

  • Create a new (empty) Include folder in your staging area.
  • Put any new files and subfolders you want added beneath it in the archive under there.
  • Add them to the archive using the same command as in the question. (The a command in 7za a... means "add to archive", so it's the same command whether or not the archive exists yet.)

Using this method,

  • Any files in the archive that are not in your staging area will remain intact.
  • Any files/folders in the staging area, but not in the archive will be added.
  • Any files in both places will be overwritten in the archive with the new one from your staging area.
0
0

Try this:

"C:\Program Files\7-Zip\7z.exe" a C:\deploy\TOP.ear C:\apps\temp\entidadejar\lib

Add the folder lib in TOP.ear, if a subfolder exists, the 7z will add the files inside the subfolder lib.

3
  • Was the dot (.) after C:\apps\temp\entidadejar\lib meant to be part of the command,  or was it just the end of the sentence? Aug 30, 2018 at 18:31
  • TOP.ear can be changed to TOP.zip or TOP.7z Aug 31, 2018 at 17:49
  • Was the dot (.) after C:\apps\temp\entidadejar\lib meant to be part of the command,  or was it just the end of the sentence? Aug 31, 2018 at 17:51
0

The command to do this is rn. From https://sevenzip.osdn.jp/chm/cmdline/commands/rename.htm:

7z rn <archive_name> <src_file_1> <dest_file_1> [ <src_file_2> <dest_file_2> ... ]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .