Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 ForEach loop

Author  Topic 

transformer
Starting Member

4 Posts

Posted - 2011-10-29 : 04:47:49
hello everyone,

I have following folders in D:\input

job1

job2

all I wanted from foreach loop to get the names of all folders from D:\input. so in other words I want SSIS to look into D:\input and tell me names of folder in there one by one. can anyone please help to find the answer?

Many thanks.

transformer
Starting Member

4 Posts

Posted - 2011-10-29 : 07:35:40
hi,
I have just find the solution to this one, just pasting here in case anybody else faces same issue.

I used a script task and get the folder list as
string[] subFolder = System.IO.Directory.GetDirectories(@"C:\TestFolder");
then I assigned this to a object variable from SSIS and then used that variable in Foreach from variable enumerator.

thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-29 : 09:36:26
just being curious here, can i ask what you're doing after iterating through the folders?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

transformer
Starting Member

4 Posts

Posted - 2011-10-29 : 21:55:22
hi Visakh16,
hmmm I have a requirement where my client will give me a input directory and will place multiple(not known at this time) folders in it. we call these folders a job, each job will have a unique name and it will have some 20 odd raw files in it. I need to iterate through my input folder, find all jobs. transform all the data in each job and place the output file(a single file) in another location. the output filename needs to be same as that of job.
there is more complexity to it. but I think you will see now why I needed to loop through.
cheers.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-29 : 23:39:31
if you will have file inside folders, why not use foreach loop with file enumerator?

http://www.sqlis.com/sqlis/post/Looping-over-files-with-the-Foreach-Loop.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -