Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DTS Problem Unziping Files

Status
Not open for further replies.

AnaFlor

Programmer
Mar 17, 2004
65
PT
Hello,

I have a source file that is zipped.
I want to create a DTS that unzip the file and then use that file to load data into the database.

How can I do this?

Thanks
 
Pretty easy to do BUT you will need to buy a licensed copy of WinZip ... and as often as EVERYONE uses it ... its worth buying a copy just once - LOL.

You will also have to download the current version of the WinZip Command Line interface from their site.

The reason for the license is that when you register Winzip, it removes the commercial/company header message from being displayed when you run Winzip in the command line. If you do not register the software, the Unzip will hang. So in say that ... here is the code to unzip a file thru SQL Server ...
Code:
declare @ZipFileName VarChar(50)
declare @SQLCommand  VarChar(400)

SET @ZipFileName = 'MyZipFile.Zip'

SET @SQLCommand = 
'exec master..xp_cmdshell ' + '''' + 'C:\MyDir\Winzip\WZUNZIP -yb  C:\MyDir\' 
+ @ZipFileName + ' C:\MyDir\' + ''''

EXEC (@SQLCommand)

What the code is doing above is starting WZUNZIP that has been installed in the C:\MyDir folder. It is Unzipping a zipped file called MyZipFile.zip which was passed in as a variable. It will unzip the file to the C:\MyDir folder.

This should get you most of the way! Enjoy!


Thanks

J. Kusch
 
What if my ziped file and the file inside it is dynamic.
Imagine that I receive one file for each day and the name is exampleyyyymmdd?

How can I solve that?

Thanks
 
declare @ZipFileName VarChar(50)
declare @SQLCommand VarChar(400)

SET
@ZipFileName = 'MyZipFile.' + CONVERT(Char,GetDate(),112)

SET @SQLCommand =
'exec master..xp_cmdshell ' + '''' + 'C:\MyDir\Winzip\WZUNZIP -yb C:\MyDir\'
+ @ZipFileName + ' C:\MyDir\' + ''''

EXEC (@SQLCommand)



Thanks

J. Kusch
 
Hi,

I am interested to learn command line zip and unzip . Where do I get the program where it help me run the zip / unzip command line.
thanks
Al
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top