Trent Tamura
Trent Tamura

Reputation: 1145

Can you use ADF to copy a file to an existing Zip folder in a way that it will add that file to the other files within the zip folder?

I could not find a way to do this, I continue to get error that a directory already exists, but I am using zipDeflate on the sink side, and no compression on source side of copy activity. My goal is to add this file to the zipped folder here:

Zipped Folder and File

and here is the contents of the zipped folder: enter image description here

My expectations would be that I could use ADF to just add the file in the first screenshot to this zipped folder, but I have found no way to do this. I have used ADF to uncompress zipped folder and files, and the opposite compressing a single file or folder, but never been able to add a file to a pre-existing zip folder.

Upvotes: 0

Views: 159

Answers (1)

Joseph  Xu
Joseph Xu

Reputation: 6083

I think we need to use Azure function to do this. Create a PowerShell function in Azure.

  1. Powershell code: adding a file to the existing zip-file.
#Add file to existing zip-file
Function AddtoExistingZip ($ZIPFileName,$NewFileToAdd)
{
    [Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | Out-Null
    $zip = [System.IO.Compression.ZipFile]::Open($ZIPFileName,"Update")
    $FileName = [System.IO.Path]::GetFileName($NewFileToAdd)
    [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($zip,$NewFileToAdd,$FileName,"Optimal") | Out-Null
    $Zip.Dispose()
}​
  1. Use azure function activity in ADF to trigger the powershell cmd.

Upvotes: 1

Related Questions