6

I am looking for a command line command to comress a file. I want to compress each file individually to filename.zip.

all the methods that I found including: http://exchangeserverpro.com/powershell-script-iis-logs-cleanup/

and:

https://stackoverflow.com/questions/17546016/how-can-you-zip-or-unzip-from-the-command-prompt-using-only-windows-built-in-ca/26843122#26843122

are near by but not exactly what I need. any suggestion? if it possible, I would like it to happen wthout external software (like 7-zip). it can be a power shell script.

barlop
  • 25,198
user110242
  • 61
  • 1
  • 1
  • 2

3 Answers3

8

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:

Special thanks to @Ramhound

0

You can compress files without any any third party software

compact [{/c|/u}] [/s[:dir]] [/a] [/i] [/f] [/q] [FileName[...]]

for more check below link https://technet.microsoft.com/en-us/library/bb490884.aspx

-2

there is no good/ easy way of doing, what yo're asking for. It is possible to do it using PowerShell /.Net as described in the topics you link to in the question, but this is quite complicated. Much easier solutions are to use third party tools like GZIP or 7-zip, or to use Windows build-in compress command, rather than using zip-files.