Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSIS Packge to locate the latest file with particle file name, unzip the file and import into a table Expand / Collapse
Author
Message
Posted Tuesday, August 20, 2013 11:02 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 11:03 AM
Points: 40, Visits: 211
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!
Post #1486371
Posted Tuesday, August 20, 2013 1:32 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 12:49 AM
Points: 12,949, Visits: 10,719
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1486415
Posted Tuesday, August 20, 2013 1:46 PM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 11:03 AM
Points: 40, Visits: 211
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!
Post #1486421
Posted Tuesday, August 20, 2013 11:39 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:29 AM
Points: 5,078, Visits: 11,858
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1486524
Posted Thursday, August 22, 2013 6:26 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 10:34 AM
Points: 386, Visits: 624
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,

Post #1487208
Posted Thursday, August 22, 2013 6:52 AM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, September 2, 2014 11:03 AM
Points: 40, Visits: 211
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!
Post #1487217
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse