使用windows自带的命令进行文件或文件夹的压缩

您所在的位置:网站首页 windows10文件夹怎么压缩 使用windows自带的命令进行文件或文件夹的压缩

使用windows自带的命令进行文件或文件夹的压缩

#使用windows自带的命令进行文件或文件夹的压缩| 来源: 网络整理| 查看: 265

需求:因为是作为服务器端的,不想安装任何第三方软件,所以决定使用windows自带的命令进行文件或文件夹的压缩

方法一:

打包单个文件:makecab src.txt tar.zip 

解压单个文件:expand src.txt tar.zip

方法二:

解决过程:

通常我们使用C:\Documents and Settings\root\SendTo\压缩(zipped)文件夹这个功能进行压缩,但是可以查看这个仅仅是 Explorer shell command,具体解释可以查看原文链接

因为不是一个可执行程序,所以我们无法通过在cmd中直接调用,貌似无法进展了

既然无法直接调用,那我们可以通过间接调用,通过VSB脚本调用COM接口从而调用自带的zip,因为SCript.exe从Windows98开始就默认安装了。有了思路就开始解决吧

编写VBS脚本,zip.vbs

Set objArgs = WScript.Arguments ZipFile = objArgs(0)   ' Create empty ZIP file and open for adding CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar) Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)   ' Add all files/directories to the .zip file For i = 1 To objArgs.count-1   zip.CopyHere(objArgs(i))   WScript.Sleep 10000 'REQUIRED!! (Depending on file/dir size) Next

调用脚本 cscript zip.vbs target.zip sourceFile1 sourceDir2  实例:

当然如果你更懒的话可以编写一个bat处理脚本直接写好需要压缩的文件双击运行即可

例如:zip.bat

set SRC=d:\src.txt set TAR=d:\tar.zip   echo 'begin zip files' cscript d:\zip.vbs %TAR% %SRC% echo 'success' pause

参考链接:

windows自带zip说明:http://filext.com/faq/compressed_zip_folder.php

VBS脚本:http://superuser.com/questions/110991/can-you-zip-a-file-from-the-command-prompt-using-only-windows-built-in-capabili  



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3