Untitled

Anonymous
Plain Text
09/16/2025 10:38 PM
659 B
19
Indexable
Never
# at top you should already have:
# Add-Type -AssemblyName System.IO.Compression.FileSystem

function Add-File-ToZip($zipPath, $srcPath, $entryName) {
  $zip = [System.IO.Compression.ZipFile]::Open($zipPath, [System.IO.Compression.ZipArchiveMode]::Update)
  try {
    # delete existing entry if present (case-insensitive)
    $existing = $zip.Entries | Where-Object { $_.FullName -ieq $entryName }
    if ($existing) { $existing.Delete() }

    # call the extension method via the static class:
    [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip, $srcPath, $entryName) | Out-Null
  }
  finally {
    $zip.Dispose()
  }
}
Editor is loading...
Leave a Comment