SSIS: Foreach Loop Container

Hi, there are many data files in the folder and I'd like to know the order they will be processed. I am using Foreach Loop Container. Does anyone know how it loops through the files, in alphabetical order or ... ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think that it will order by filename, but I haven't tested it very much!  Try putting some files in named a.txt, b.txt, c.txt, etc., but don't add them to the folder in that order. Then see what you get.

To be certain of your order you could read then in in a foreach loop, placing them into a table. Then read the table in the proper order into an Object Variable, and have a ForEach loop read the object variable and not directly from the disk.


Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
The order of file loading is not predictable.  

If you require an ordered loading, I'd use the first ForEach loop to get all file names and insert them into a table.  
Then do a SQL Task to select that list, ordered by however you wish.
Then, go through a loop to set the source to that path-file, and load.
ValentinoVBI ConsultantCommented:
My experience is that files are always processed alphabetically on filename in ascending order.  This order is not guaranteed but to be honest I've never seen it behave any differently.  So you might want to take that small risk and indeed assume they are treated alphabetically.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.