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

  • 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!

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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!

  • 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.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • 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,

  • 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!

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply