English 中文(简体)
只使用 7z 压缩文件而不保存路径
原标题:Compressing only files using 7z without preserving the path

我正在使用 7z 命令行可执行到 zip 文件, 但我看到, 在添加归档的同时, 文件路径会被保存在归档中 。

所以,如果我这样做

7z a -tzip  myzip.zip dir1dir2*

the archive myzip.zip will contain the path dir1dir2. I do not want this, rather I want only the files to be added to the zip file without the paths being preserved. I searched quite a bit but do not seem to find any way of doing this, maybe I am missing something obvious?

谢谢 谢谢

最佳回答

Give the full path. That should work. Not the relative path from the current location. For example, I give the below, where I want the files in the man5 folder to be archived.

$ 7z a -tzip myzip.zip /home/pradeeban/Desktop/man4/man5/*

拉链只包含文件, 没有目录 。

然后我只给出了相对路径。它有目录,在拉链里。

$ 7z a -tzip myzip.zip Desktop/man4/man5/*

尝试 Linux (Ubuntu 12.04) 。 不知道这是否与 Windows 不同 。

问题回答

Just add a dot before the path, i.e. 7z a -tzip -r myzip.zip .RelativeDir*

我发现了一种方法,通过使用相对路径来做到这一点:

7z a -tzip  myzip.zip %CD%dir1dir2*

% CD% 是您如何在 Windows 批量文件中获取当前路径, 但它也可以从命令行获得 。 更多关于 < a href=" http://blogs. msdn.com/b/ oldnewthing/ archive/2005/01/ 28/36265. aspx" rel= “ noreferrer” > 从批量文件中获取当前目录 的信息 。

这对我很管用

考虑文件夹结构如 C: ParrentSubFolders... 。 您想要创建父文件夹.zip, 它将包含所有文件和文件夹 C: 没有父文件夹的父文件夹 [, 它将从 SubFolders 开始...]

cd /D "C:Parent"

"7z.exe" a Parent.zip "*.*" -r

这将在 C: 父子关系中创建父子关系. zip





相关问题
Command Line Parameters

I m trying to add my file in Visual Studio as command line parameters. I know my code works since when I use fopen("whole path here", "r"), it runs. I then add the file as a command line parameter ...

Read from File, or STDIN

I ve written a command line utility that uses getopt for parsing arguments given on the command line. I would also like to have a filename be an optional argument, such as it is in other utilities ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

热门标签