What Can I Use To Unzip A File

broken image


By: Bhavesh Patel | Updated: 2019-03-19 | Comments (4) | Related: More >Integration Services Development

Select the file you wish to extract from the split ZIP files. You also can select entire folders or select multiple files by holding down the 'Ctrl' key while clicking on files. Click the 'Extract To' button at the top of the screen. Navigate to the location where you wish to save the files to and click the 'OK' button. In order to compress files/folders into a ZIP file or extract files from a ZIP archive in Windows 10, people tend to use software like WinZip or 7-Zip. Actually, Windows systems come with built-in Compressed Folder Tools so that users can compress and uncompress files/folders even without WinZip or any other outside zip tools installed.


Free MSSQLTips Webinar: Getting Started with SSIS

Learn how to get started with SQL Server Integration Services and how to build an SSIS project with this demo focused webinar.


Problem

There is often a need to zip and unzip files that we get that need to processwithSQL Server Integration Services (SSIS). There are several different tools that exist that have this functionality. In this tip, I will show the steps on how to zip and unzip files using 7-Zip as partof a SQL Server Integration Services package.

Solution

We can use any file extractor in SQL Server Integration Services, but for thisdemonstration I am going to use 7-Zip to zip and unzip folders and files. Beforejumping into the SSIS package we should cover some basics of 7-Zip.

About 7-Zip File Archiver

7-Zip is a file archiver with a high compression ratio usingLZMA andLZMA2 compression. Its free software and open source. It has self-extractingcapabilities for 7Z format and strong AES-256 encryption in 7z and ZIP formats.To install 7-Zip, you can download7-Zip for Windows.

After installing the 7-Zip on my PC, here is the 7-Zip installation location.

This is the location where I want to zip files.

Zip Files Using 7-Zip in SQL Server Integration Services Package

I created a new SSIS project and named it 'Zip_UnZip_Using7zip_SSIS'then dragged an Execute Process Task from the SSIS Toolbox to the Control Flow andrenamed it 'ZIP Data'.

As per MSDN, theExecute Process Task runs an application or batch file as part of a SQL ServerIntegration Services package workflow. Although you can use the Execute Processtask to open any standard application, you typically use it to run business applicationsor batch files that work against a data source.

Here are the settings for the Execute Process Tasks.

RequireFullFileNameThe task should fail if the executable is not found at the specifiedlocation.
ExecutableName of the executable to run.
ArgumentsCommand prompt arguments.
WorkingDirectoryPath of folder that contains executable, or click the browse button(...)and locate the folder.
StandardInputVariableSelect a variable to provide the input to the process, or clickNew variable... to create a new variable.
StandardOutputVariableSelect a variable to capture the output of the process, or clickNew variable... to create a new variable.
StandardErrorVariableSelect a variable to capture the error output of the processor, or clickNew variable... to create a new variable.
FailTaskIfReturnCodeIsNotSuccessValueIndicates whether task fails if process exit code is different fromthe value specified in SuccessValue.
SuccessValueSpecify the value returned by the executable to indicate success. Bydefault, this value is set to 0.
TimeOutSpecify the number of seconds that the process can run. A value of0 indicates that no time-out value is used, and the processruns until it is completed or until an error occurs.
TerminateProcessAfterTimeOutIndicates whether process is forced to end after the time-out periodspecified by the TimeOut option. This option is availableonly if TimeOut is not 0.
WindowStyleSpecify the window style in which to run the process.

Now right click the task and choose 'Edit…' to open the ExecuteProcess Task Editor and then click 'Process' on the left and change theexecutable path, arguments and working directory as follows and keep the othersas the defaults. I explain this further down.

Executable

Put the full path to the executable as: C:Program Files7-Zip7z.exe

Arguments

Provide the command prompt arguments: a -t7z 'D:BulkFiles.ZIP' 'D:BulkFiles*.*'

  • I am going to archive the files using the 'a'command argument.
  • The format is specified with the -t switch -t7z
  • Put all files into the zip file 'D:BulkFiles.ZIP'
  • From location 'D:BulkFiles*. *'

Here is a link to theCommand Lind Commands and here is a link toCommand Line Switches.

Working Directory

The Execute Process Task will change directories to this location. If an EXEwrites to an output file in the current directory, this file will be located whereverthe working directory is pointing. Here I am going to add a zip file on D:drive.

Running the SSIS Package to Zip Files

Now the package is set for archiving the data.

As per the configuration, all files are zipped into BulkFiles on the drive 'D:'.

Unzip Files Using 7-Zip in SQL Server Integration Services Package

I will add to the SSIS package another Execute Process Task to extract the fileswe just zipped up.

Here are the settings to unzip the files.

Executable

Put the full path to the executable as: C:Program Files7-Zip7z.exe

Arguments

Provide the command prompt arguments: e 'D:BulkFiles'

  • I am going to extract the files using the 'e'command argument.
  • This will extract the file 'D:BulkFiles'

Here is a link to theCommand Lind Commands and here is a link toCommand Line Switches.

Working Directory

How

The Execute Process Task will change directories to this location. If an EXEwrites to an output file in the current directory, this file will be located whereverthe working directory is pointing. Here I am going to add a zip file on D:drive.

Running the SSIS Package to UnZip Files

Here is the package.

If we look on the D: drive we can see the extracted files.

SQL Server Integration Services Execute Process Task Use

  • The Execute Process Task can be used to execute an application, executablefiles, batch files inside a SSIS execution.
  • As per this scenario, we can also use RAR/Winzip/PeaZip/Jzip to performcompression/decompression of files and folders.
  • We can also execute standard applications like (Winword, Excel, Powerpoint,etc.) and custom application (C#.Net,Vb.Net,etc).
  • It's easy to integrate variables, parameters and arguments.
  • If you need to execute Windows command line commands such as RENAME, DEL,COPY, DIR you use the cmd.exe utility with this task.
Next Steps

How Do I Unzip File

  • Kindly ensure to test with a test server first before rolling out to production.
  • Additional Reading
    • SQL Server Integration Services (SSIS) Tutorial.
    • SSIS Zip Files.
    • CheckoutExecute Process Task.

Last Updated: 2019-03-19



About the author

What Program Can I Use To Unzip A File

Bhavesh Patel is a SQL Server database professional with 10+ years of experience.
View all my tips

How Do I Unzip Downloaded Files

Related Resources





broken image