Many a time we need to zip or unzip more then one file present in a folder. SSIS provides a easy way to handle this.
For my example I am using 7-zip though we have many other compress software like (pkzip or winzip)
Steps to zip/unzip files
A) Declare a variable FileName as string datatype
B) Use ForEach loop to loop through the files in the folder and map file names to FileName variable
a) Provide folder name inEnumerator configuration
b) map FileName Variable
C) Use Execute Process task to zip/unzip to individual files
a) Browse to Exe of 7z in Executable
b) Use expression to configure the argument
D) Execute the package
Use the files........
Subscribe to:
Post Comments (Atom)
Google Dataset Search
Google's Vision statement is “ to provide access to the world's information in one click. ” Google’s mission Statement is “ ...
-
Q1. WHAT is SQL Server Reporting Services(SSRS)? SQL Server Reporting Services is a server-based reporting platform that you can use to cre...
-
Many times I have been asked by SSIS programmers that they face difficulties when they need to select some specified columns and rows or the...
-
This is a reference answer to a post on MSDN forum but is very useful Question: While copying and renaming a file to a dynamic location...
Dear Rahul,
ReplyDeleteThank you for posting this topic, very very helpfull to see a step-by-step guide with screenshots.
Namasté,
Gahan Zwart
I am trying to do this in a stored procedure. The 7zip program is executing but the return is that it can not find the archive. I have a print statement to see what I am passing to the OS and if I copy / paste it my command line works. But does not find the file from SQL execution. Any ideas anyone.
ReplyDeleteC:\7zip\7zip\7z.exe e C:\Users\jwilliams\Documents\EConnect\FirstMerrit\SourceFiles\810571sn_4.zip pP810571
The above it the result of running my SQL script.
HEre is the actual SQL script:
ALTER PROCEDURE UnZipFile @CustomerID int
AS
declare @ZipFileName VarChar(max)
declare @SQLCommand VarChar(max)
DECLARE @DataZipPass as varchar(10)
SELECT @DataZipPass = DataZipPass
FROM Customers
WHERE Customers.CustomerID = @CustomerID
SET @ZipFileName = 'C:\Users\jwilliams\Documents\EConnect\FirstMerrit\SourceFiles\810571sn_4.zip'
SET @SQLCommand =
'exec master..xp_cmdshell ' + '''' + 'C:\7zip\7zip\7z.exe e '
+ @ZipFileName + ' p' +@DataZipPass + ' -y ' + ''''
PRINT 'Extraction Command sent: ' + cast(@SQLCommand as varchar(max))
PRINT ''
EXEC (@SQLCommand)
This comment has been removed by the author.
ReplyDeleteHello, it was a really good example. it helped me in completing Unzip file task. i have a small query...
ReplyDeletei need the name of output file.
i provided param StandardOutputVariable = @[User::NewFileName]
but i can't capture the filename.
am i missing something
@ashish: to get output file name depends on the utility you would use.
ReplyDeleteStardardOutputVariable will get all the information return from the process,if the utility returns the just the file name..you are gud but usually Utilities return lot of information back like success status, size etc and file name is just one of them.
I getting the following error: The process exit code was "7" while the expected was "0"
ReplyDeleteCan you please help me how I can fix this error.
Thanks
@ "I getting the following error: The process exit code was "7" while the expected was "0"
ReplyDeleteCan you please help me how I can fix this error"
There must be some error, might be in command stmt.. could you get the stmt and run it in command prompt or paste here so that i can look at it.
THANKS FOR EXCELLENT WORK RAHUL. I APPLIED TO MY TEST AND IT WORKS LIKE CHARM.
ReplyDelete@shahbaz...pleasure!!
ReplyDeleteHi...I'm also getting the prcess exit code was 7 - please help
ReplyDeleteI'm also getting the error:the process exit code was "7" while the expected was "0" - please help
ReplyDeleteThanks, this was just what I needed. It solved my problem and gave me a crash course in programming integration services packages.
ReplyDeleteHello Rahul,
ReplyDeleteCan you please explain your arguments used?
Iam getting below error ,Please help
ReplyDeleteThe process exit code was "7" while the expected was "0".
Hi, I tried to unzip a file using 7zip at command line with the following command:
ReplyDeleteC:\Program Files\7-Zip>7z e c:\easy.zip -oc:\new folder\
I got the following error:
No files to process
Files: 0
Size: 0
Compressed: 4790659
C:\Program Files\7-Zip>
Please help.
What am I doing wrong?
Hurray, thanks! Worked first time.
ReplyDeleteI appreciate your tutorial it helped me a lot! Thank You!!
ReplyDeleteJeff
what is @[User::NewFileName]
ReplyDeleteAge is an issue of mind over matter. If you don't mind, it doesn't matter. See the link below for more info.
ReplyDelete#issue
www.ufgop.org
Hi Rahul,
ReplyDeleteCould you please tell me What 'e -oc:/rahul' is in Argument??
You have made nice post but you can know more about 7-zip (compressor/extractor) it at:
ReplyDeletehttps://basusoftgame.blogspot.com/2017/12/7-Zip-Unzip-file-for-Windows.html