如何使用命令行压缩指定文件夹
你们能告诉我如何将指定的文件压缩到同一个 Zip 文件中吗?让我告诉我我的文件夹是如何填充的:
- 任务调度程序每天都会备份我的数据库并将它们保存到文件中。它每天创建 4 个数据库备份,这意味着每天会多出 4 个文件。因此,我需要将新创建的备份压缩到同一个 zip 文件中(当然它与前一天的 zip 文件不同,将为当天新创建的备份文件创建 zip 文件),并且我需要自动执行此操作。好吧,我知道如何让它自动化。我可以使用 Windows 任务计划程序来自动化操作。
谢谢。
Could you people tell me how to zip specified files into same Zip file. Let me tell how my folders are filled :
- A task scheduler have backups of my databases and save them into a file daily. It creates 4 database backup daily which means there will be 4 more files daily. So I need to zip newly created backups into same zip file (of course it differs from previous day zip file, the zip file will be created for that day for newly created backup files) and I need to do it automatically. Well I know how to make it automatic. I can use Windows task scheduler to automate things.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用开源程序 7Zip ,其命令行如下:
如果您使用的是 NTFS 分区,让 Windows 自动压缩备份文件所在的文件夹也可能会解决您的问题(右键单击您的文件夹,选择“属性”、“高级”,然后单击“压缩内容以保护数据”)。
I use the open source program 7Zip with a command line like:
If you're using an NTFS partition, it might also solve your issue to have Windows automatically compress the folder your backup files are in (right click on your folder, select Properties, Advanced, and click Compress contents to secure data).
您可以使用 DotNetZip 来完成此操作 - 它最初是作为供程序员使用的库而生成的,但示例应用程序构建于并随库一起提供,它们本身就变得非常有用。
其中一个“示例”称为 zipit.exe - 一个控制台工具。指定一个不存在的 zip 文件来创建新文件,或指定一个现有的 zip 文件来更新它。
您可以指定一个或多个文件名、目录或描述要包含哪些文件的逻辑表达式。对于表达式:
name = *.jpg
任何 .jpg 文件。
mtime> 07/01/2009
最后修改时间在 2009 年 7 月 1 日午夜之后的任何文件。还有 ctime 和 atime 表示创建时间和访问时间。
ctime> 07/01/2009:07:53:00
创建时间在 2009 年 7 月 1 日上午 7:53 之后的任何文件。
size > 320mb
任何大小超过 320mb 的文件。您也可以使用 kb 或 gb。或者省略字节大小的字符。并且您可以使用 <或 = 作为操作。
attr != H
任何未设置隐藏属性的文件。其他属性包括 S=系统、R=只读、A=存档。当然,您也可以测试该属性是否为 ON(使用 = 而不是 !=)。
attr != H 和尺寸 > 320mb
包括满足这两个条件的文件。您还可以使用 OR 作为连词。使用括号对复杂表达式进行分组。
名称 = *.jpg 或名称 = *.gif
包括满足一个或另一个条件的文件。
(名称 = *.jpg)或(名称 = *.gif)
同上。
(mtime >= 07/01/2009) 和 (mtime < 07/02/2009)
7 月 1 日修改的任何文件。从午夜到午夜。
(name = *.jpg) AND (mtime >= 07/01/2009) and (mtime < 07/02/2009)
7 月 1 日修改的任何 .jpg 文件。
(名称 = *.jpg)和(大小 >= 100kb)和(运行时间 >= 07/01/2009)和(运行时间 <07/02/2009)
任何 .jpg 文件,大小为 100kb 或以上,并于 7 月 1 日修改。
使用 zipit.exe 工具上的其他选项,您还可以:
示例:
zipit.exe Archive.zip -D c:\project1 -r+ "(name = *.xlsx) and (mtime >= 07/01/2009) and (mtime < 07/31/2009)"
zipit.exe Unpack.exe -sfx w -D project2 -r+ "(name = *.pdf) and (size > 100kb)"
DotNetZip 是免费的。
所有这些功能也可在该库的 .NET 界面中使用。还有一个 GUI 工具。
You can do it with DotNetZip - it was originally produced as a library for use by programmers but the sample apps built on and shipped with the library have become very useful in their own right.
One of the "samples" is called zipit.exe - a console tool. Specify a non-existent zipfile to create a new one, or specify an existing zipfile to update it.
You can specify one or more filenames, directories, or a logical expression that describes which files to include. For the expressions:
name = *.jpg
any .jpg file.
mtime > 07/01/2009
any file with a last modified time after midnight on 1 July 2009. There is also ctime and atime for created time and accessed time.
ctime > 07/01/2009:07:53:00
any file with a created time after 7:53am on 1 July 2009.
size > 320mb
any file with a size over 320mb. You can use kb or gb, too. Or omit the characters for a size in bytes. And you can use < or = as operations.
attr != H
any file that does not have the Hidden attribute set. Other attributes include S=system, R=Readonly, A=Archive. Of course you can test that the attribute is ON as well (using = instead of !=).
attr != H and size > 320mb
include the files that satisfy both conditions. You can also use OR as a conjuction. Use parens to group complex expressions.
name = *.jpg or name = *.gif
include the files that satisfy one or the other condition.
(name = *.jpg) or (name = *.gif)
same as above.
(mtime >= 07/01/2009) and (mtime < 07/02/2009)
any file modified on July 1st. From midnight to midnight.
(name = *.jpg) AND (mtime >= 07/01/2009) and (mtime < 07/02/2009)
any .jpg file modified on July 1st.
(name = *.jpg) and (size >= 100kb) and (mtime >= 07/01/2009) and (mtime < 07/02/2009)
any .jpg file, 100kb or more in size, modified on July 1st.
With other options on the zipit.exe tool, you can also:
Examples:
zipit.exe Archive.zip -D c:\project1 -r+ "(name = *.xlsx) and (mtime >= 07/01/2009) and (mtime < 07/31/2009)"
zipit.exe Unpack.exe -sfx w -D project2 -r+ "(name = *.pdf) and (size > 100kb)"
DotNetZip is free.
All these features are available in the .NET interface of the library, too. And there's a GUI tool, too.
我放弃了 WinZip,转而使用 7-Zip,因为它快速、免费、高效且可用适用于 Windows 和 Linux。
如果您是 WinZip 粉丝,请查看 WinZip 命令行支持插件:http:// winzip.com/prodpagecl.htm
您可以归档 Windows 命令行允许的任意数量的文件或目录:
I've abandoned WinZip in favor of 7-Zip because it's fast, free, efficient, and available for both Windows and Linux.
If you're a WinZip fan, take a look at the WinZip command-line support add-on: http://winzip.com/prodpagecl.htm
You can archive as many files or directories as your Windows command line will allow:
您可以在 http://gnuwin32.sourceforge.net/packages/zip 下载适用于 Windows 的 GNU zip。嗯。如果您想获得整个 UNIX 命令行路径,可以通过 http://www.cygwin.com/< 获取 zip /a>.
手册页给出的这个示例似乎可以解决您的问题,还有许多其他命令行选项:
例如,如果 foo.zip 存在并包含 foo/file1 和
foo/file2,并且目录 foo 包含文件 foo/file1 和 foo/file3,则:
或者更简洁地说,
将替换 foo.zip 中的 foo/file1 并将 foo/file3 添加到 foo.zip。此后,
foo.zip 包含 foo/file1、foo/file2 和 foo/file3,其中 foo/file2 未更改
前。
You can download GNU zip for Windows at http://gnuwin32.sourceforge.net/packages/zip.htm. If you want to got the whole UNIX command line route, zip is available with http://www.cygwin.com/.
The man page gives this example that seems to address your problem, there are many other command-line options as well:
For example, if foo.zip exists and contains foo/file1 and
foo/file2, and the directory foo contains the files foo/file1 and foo/file3, then:
or more concisely
will replace foo/file1 in foo.zip and add foo/file3 to foo.zip. After this,
foo.zip contains foo/file1, foo/file2, and foo/file3, with foo/file2 unchanged from
before.
查看一个名为 PKZIP 的旧程序。我相信您也可以使用 WinZip 和 7Zip 来做到这一点。
Look into an old program called PKZIP. I believe you can also do this with WinZip and 7Zip.