Creating an archive from a directory without the directory name being added to the archive

Creating an archive from a directory without the directory name being added to the archive

From the 7-Zip Help file:

a (Add) command

Adds files to archive.

Examples

7z a archive1.zip subdir\

adds all files and subfolders from folder subdir to archive archive1.zip. The filenames in archive will contain subdir\ prefix.

7z a archive2.zip .\subdir\*

adds all files and subfolders from folder subdir to archive archive2.zip. The filenames in archive will not contain subdir\ prefix.

cd /D c:\dir1\

7z a c:\archive3.zip dir2\dir3\

The filenames in archive c:\archive3.zip will contain dir2\dir3\ prefix, but they will not contain c:\dir1\ prefix.

So the command you'd want would be: 7za.exe a folder1.zip .\folder1\*

Also, pay attention to 7-Zip's handling of wildcards. It doesn't treat *.* as "all files" -- it means "all files with a period in the filename." Extension-less files will be missed. If you really want all files, just use * instead.

Finally, the -tzip parameter isn't needed if the archive filename ends in .zip. 7-Zip is smart enough to figure out which format you want in those cases. It's only required when you want a custom extension (e.g. 7za.exe a -tzip foo.xpi <files> for a Mozilla Add-on).

 

 

 

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(71)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-05-14 event bus
2020-05-14 想要学习设计模式,你得先会看类图,一张图读懂UML
2020-05-14 DDD学习
2019-05-14 Where should I put <script> tags in HTML markup?
2019-05-14 Checking out pull requests locally
2018-05-14 从配置文件中删除节点
2018-05-14 remove namespace from xml config file
点击右上角即可分享
微信分享提示