0

I have a PowerShell script which should be able to create a zip of a particular folder, which is also in the same location. But the problem is I do not know where this script will be saved. I tried the code below, but I am not able to do it. The Compress-Archieve method shows the argument is null or empty. Please help.

Add-Type -AssemblyName System.IO.Compression.FileSystem
$source = Get-ChildItem -Filter -Directory .\PublishOutput
$dest = Get-Location
$f = "\Kovai.zip"
$final = Join-Path $dest $f
Write-Host $final
[System.IO.Compression.ZipFile]::CreateFromDirectory($source,$final)
Mika Sundland
  • 18,120
  • 16
  • 38
  • 50
HariHaran
  • 3,642
  • 2
  • 16
  • 33
  • This is a little vague. Do you mean to save the zip in the same location as the folder or in the same location as the script? The answer from @gvee seems to assume same as folder. – Palle Due Jan 31 '18 at 09:38
  • yeah same as the root folder where a sub folder exists which is zipped by the script and also thrown into the root folder itself. @gvee answer is what i was working on . THanks – HariHaran Jan 31 '18 at 10:14

2 Answers2

3
$folderToZip = "C:\FolderToZip"
$rootfolder = Split-Path -Path $folderToZip
$zipFile = Join-Path -Path $rootfolder -ChildPath "ZippedFile.zip"

Write-Output "folderToZip = $folderToZip"
Write-Output "rootfolder  = $rootfolder"
Write-Output "zipFile     = $zipFile"

Compress-Archive -Path $folderToZip -DestinationPath $zipFile -Verbose

Results

gvee
  • 16,732
  • 35
  • 50
0

An easy way to a compressing folder with a subdirectory enter image description here

 Compress-Archive -PAth test/* -DestinationPath a.zip
 ## replace "test" with your path 

enter image description here

Willie Cheng
  • 7,679
  • 13
  • 55
  • 68