如何在没有整个目录结构的情况下创建一个zip文件 [英] How to create a zip file without entire directory structure

查看:103
本文介绍了如何在没有整个目录结构的情况下创建一个zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个zip文件,并希望保留大多数目录结构,而不是命令行中定义的rootdir.我正在使用的命令是:

I am trying to create a zip file and want to preserve most of the directory structure, but not the rootdir as defined from the command line. The command I'm using is:

zip -r out.zip /foo/bar/

我希望它通过bar递归并添加具有保留的目录结构的所有文件(这样做).但是我不希望'foo'是所创建的zip文件中的顶级目录.我希望bar成为顶层目录.

I'd like it to recurse through bar and add all files with preserved directory structure (which it does). However I do not want 'foo' to be the top level directory in the zip file created. I would like bar to be the top level directory.

有什么简单的方法可以解决这个问题吗?我意识到我可以在压缩之前更改目录以避免该问题,但是我正在寻找不需要此方法的解决方案.

Is there any easy way to go about this? I realize I could change directories before zipping to avoid the problem, but I'm looking for a solution that doesn't require this.

推荐答案

我认为zip无法排除顶级目录.我认为您最好的选择是执行以下操作: 推/foo; zip -r out.zip ./bar;弹出;

I don't believe zip has a way to exclude the top level directory. I think your best bet would be to do something like: pushd /foo; zip -r out.zip ./bar; popd;

但这正是您说的不想要的答案.

But this is exactly the sort of answer you said you didn't want.

这篇关于如何在没有整个目录结构的情况下创建一个zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆