SSIS foreach loop file enumerator - loop through a specific order of the filenames

rss2
rss2 used Ask the Experts™
on
Hi Experts,

I have an SSIS package written in 2008, and I would like to use the foreach to read flat files from a directory one by one.

However, I want to pull the files through the foreach loop in a very specific order. It's not alphabetical.. One of the files has to go first, then the others.

Other than having that one file to go first before the foreach loop, and then process the others, is there a way in that one foreach loop to specify the order of the files?

For instance, can I read the filenames into a recordset, then have the foreach loop read from that recordset in a specific order?

Thank you!
rss2
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I would take your approach - i don't think you can guarantee the order..

1.  Create a script to import the file names in the folder to a new table.  

2.  Use an "Excecute SQL Task" to put the pull from that table, in your specific order, in to an "object" data type variable.

3.  Using the foreach - iterate through in your order.

Commented:
yes you can save the files (pathname + filename) into a recordset and read it from a for each loop!
Do you need an example?
regards,
Pedro

Author

Commented:
Thank you, yes, I would be greateful for an example.

Also, do you know how I can re-order the rows in the recordset, so i can specify the order of the filenames coming out of the recordset into the foreach loop?

Thank you!

rss2
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
I'll do an example now..
just a moment...
Commented:
Here you have...
add the attached package to a SSIS Package, update the strFilename variable in SSIS and the connections.
Helped?
regards
Pedro
SSIS-Interface.JPG
Package-EE133-dtsx.txt
MyPaths.txt
bFile.txt
aFile.txt

Commented:
Improvements!?

Commented:
Could you please give feedback to this question? Problem solved?!
Regards,
pedro

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial