There is a single, simple cmd.exe command for this (through PowerShell v5.0+).
To zip:
powershell Compress-Archive -LiteralPath 'C:\mypath\testfile.txt' -DestinationPath "C:\mypath\Test.zip"
To unzip:
powershell Expand-Archive -LiteralPath "C:\mypath\Test.Zip" -DestinationPath "C:\mypath" -Force
Sources:
3. 使用 wscript:
Here is an all batch file solution (a variation of my other answer) that will zip a file named c:\ue_english.txt
and put it in C:\someArchive.zip
:
set FILETOZIP=c:\ue_english.txt
set TEMPDIR=C:\temp738
rmdir %TEMPDIR%
mkdir %TEMPDIR%
xcopy /s %FILETOZIP% %TEMPDIR%
echo Set objArgs = WScript.Arguments > _zipIt.vbs
echo InputFolder = objArgs(0) >> _zipIt.vbs
echo ZipFile = objArgs(1) >> _zipIt.vbs
echo CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" ^& Chr(5) ^& Chr(6) ^& String(18, vbNullChar) >> _zipIt.vbs
echo Set objShell = CreateObject("Shell.Application") >> _zipIt.vbs
echo Set source = objShell.NameSpace(InputFolder).Items >> _zipIt.vbs
echo objShell.NameSpace(ZipFile).CopyHere(source) >> _zipIt.vbs
echo wScript.Sleep 2000 >> _zipIt.vbs
CScript _zipIt.vbs %TEMPDIR% C:\someArchive.zip
pause