SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSIS Packge to locate the latest file with particle file name, unzip the file and import into a...


SSIS Packge to locate the latest file with particle file name, unzip the file and import into a table

Author
Message
SQLArnold
SQLArnold
SSC-Enthusiastic
SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)

Group: General Forum Members
Points: 183 Visits: 338
Hello All,
I have been working on an this issue for a couple of months and I have searched and reviewed several blogs, websites and articles and cannot find a complete answer to my problem. I need to be able to import a zipped file into a table to report on the data.

A zipped file is dropped to a folder and I need to create a SSIS package to run each day and see if there is a file created that day. If yes unzip the file and import the file into a SQL Server table, which is already created. Then once the data is in the table I can complete reporting on it. I have been manually unzipping the file and then importing the file. I would like to automate this process.
File Name of the zipped file
FILE.PDERESP.ANT591.DT080813.TM002506.ZIP

Break down of the zipped filename
the zipped file begins with
FILE.PDERESP.ANT591.DT

Then
080813 = mmddyy

Then
TM002506 = this part of the filename changes

unzipped filename looks like this with no extension but it is a txt file.
ANT591.PDERPDE0808001

I use a foreach loop to locate the latest file and then use an execute process task to unzip it with WinZip into the same folder location with the arguments in an expression
"-min -e -o -j " + @[User::ZipFileName]

Do I need another foreach loop to locate the unzipped file or is there a way to import the zipped file or from within the WinZip once it opens.

Is there a way to have the execute process task to store the unzipped file name as a standard output variable?

Thank you in advance for your time and assistance.

Cheers!

Tim Harms

The pain of Discipline is far better than the pain of Regret!
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27741 Visits: 13268
An option might be to extract the file to a folder called Extract. Then you can go with a for each loop to that folder and pick up the file there. No variables or output needed.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
SQLArnold
SQLArnold
SSC-Enthusiastic
SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)

Group: General Forum Members
Points: 183 Visits: 338
Thank you for your reply it is greatly appreciated.
I thought I would have a problem deleting the file after I moved it. Our DBAs allow business analysts to have minimal access but by searching again I think I might have found a solution. Everything I researched before used xp_delete_file.
Thank you again for your time, I will give this second try.

The pain of Discipline is far better than the pain of Regret!
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18893 Visits: 20460
SQLArnold (8/20/2013)
Thank you for your reply it is greatly appreciated.
I thought I would have a problem deleting the file after I moved it. Our DBAs allow business analysts to have minimal access but by searching again I think I might have found a solution. Everything I researched before used xp_delete_file.
Thank you again for your time, I will give this second try.


No need for that - you can use the SSIS-native File System Task to delete the file.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
aaron.reese
aaron.reese
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1047 Visits: 902
TM002506 = this part of the filename changes


Is it always the same length?
Is it always the last part before the zip?

you could strip the .zip from the filename and then find the strpos of the last period (.) and take everything to the left of that as the filename,
SQLArnold
SQLArnold
SSC-Enthusiastic
SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)SSC-Enthusiastic (183 reputation)

Group: General Forum Members
Points: 183 Visits: 338
Hello Aaron,
Here are some more samples of the unzipped file names, it does appear the filename are alway the same length of 23.
1 2
123456901234567890123
ANT591.PDERPDE0820002
ANT591.PDERPDE0820001
ANT591.PDERPDE0807001
ANT591.PDERPDE0808001

I am not sure what you mean, I have been able to locate the zipped file and unzip it but the zipped filename and the unzipped filenames are not the same. Maybe I misunderstood, can you explain, please?


I have been figuring out that (WinZip) zipping through SSIS is a difficult task. I am also trying to free up some space in a folder that has 300+ files. I would like to have a foreach loop locate each file, zip it then move to the next unzipped file. I keep getting error messages, "No files were found for this operation - Nothing to do" or "Cannot open file: it does not appear to be a valid archive.

I am using a foreach loop to locate the file name passing the filename inside the foreach loop to excute process task with arguments expression "-min -a -en " + @[User::flatFileName] or have tried "-min -m -en " + @[User::flatFileName]. Any ideas whereI could more information?

Thanks,
Tim

The pain of Discipline is far better than the pain of Regret!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search