loop problem?
Hi Everyone,
I have a monthly .txt.gz file dump thats zipped in .gz format. Each month the name changes to reflect the month and year (2011.06.01_all.txt.gz)(2011.07.01_all.txt.gz)...etc.
I was able to build the process of unzipping all the files into a 'working folder' with 7-zip, upload the data into SQL, and delete. However, how would I set it to collect only the newest file? At the moment, it's only uploading from the 07/2011 since
it's the file name that raw file connection manager is set on. Is there a way to set it as a variable and only collect the newest file? I know its a loop process, but I have no idea how to set it up...
Thank you in advance for any guidance you can provide.
July 22nd, 2011 5:55pm
I'm not sure I understand all the aspects of your scenario...
You can use a Foreach Loop Container to iterate over all the files in a particular folder by using the Foreach File Enumerator. If you only ever have one file in there, but the name of that file changes constantly, then this can work for you to populate
a variable with that file's name.
If you have many files in the folder, and you want the "newest" file, then you can still use the Foreach Loop Container - but you'll have to put some logic inside the container to collect the "newest" file - however you determine what "new" is. You
can use a Script Task to examine the current file's name, compare it to another variable in which you store the "newest" file name, and update the "newest" variable if it's newer. You can use the System.IO namespace or a File Properties custom task to
retrieve the file's modified date/time (instead of going from the filename).
That should get you started...
Talk to me now on
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2011 7:27pm
you have two approaches,
First: using foreach loop container; as Todd described
Second : using script task to find out latest file, a sample of finding latest created file or modified file is here:
http://www.rad.pasfu.com/index.php?/archives/30-Find-Last-Created-File-in-Special-Directory-SSIS.htmlhttp://www.rad.pasfu.com
My Submitted sessions at sqlbits.com
July 23rd, 2011 12:54am


