dbTalk Databases Forums  

ForEach Loop, getting filename - help?

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss ForEach Loop, getting filename - help? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
unc27932@yahoo.com
 
Posts: n/a

Default ForEach Loop, getting filename - help? - 02-12-2006 , 03:39 PM






Using 2005, SSIS...

OK - I'm trying to loop through all the *.txt files in a certain
directory, and using each filename, call an executable, passing the
filename as an argument to the executable. I started by adding a
foreach loop container, and made sure it was foreach file enumerator
type. I chose the appropriate directory, and put in my *.txt filter,
and chose to use the fully qualified name. On the variable mappings
page, I created a new variabe (User::FileName), and saved it. Then I
added the execute process task inside the for each loop container,
calling the executable in the execute process task. I then chose the
User::FileName variable as the StandardInputVariable. And it won't
work. It can't find the filename at all. It does it 3 times (which is
the # of files) but it's not finding the filename.

What do I need to do in order to get the filename passed to the
executable???


Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: ForEach Loop, getting filename - help? - 02-12-2006 , 04:21 PM






Hello Corey,

So are you saying that the variable does not contain the value or that the
ExecuteProcess task is unable to use it?

If the former then have a look at this article in which we discuss doing
what you are trying to do

http://www.sqlis.com/default.aspx?55


You could add a breakpoint on the ForEach enumerator to break on each iteration
of the loop. This way you can use a watch to find out wht value is being
stired in the variable.




Allan Mitchell
www.SQLDTS.com
www.SQLIS.com
www.Konesans.com

Quote:
Using 2005, SSIS...

OK - I'm trying to loop through all the *.txt files in a certain
directory, and using each filename, call an executable, passing the
filename as an argument to the executable. I started by adding a
foreach loop container, and made sure it was foreach file enumerator
type. I chose the appropriate directory, and put in my *.txt filter,
and chose to use the fully qualified name. On the variable mappings
page, I created a new variabe (User::FileName), and saved it. Then I
added the execute process task inside the for each loop container,
calling the executable in the execute process task. I then chose the
User::FileName variable as the StandardInputVariable. And it won't
work. It can't find the filename at all. It does it 3 times (which is
the # of files) but it's not finding the filename.

What do I need to do in order to get the filename passed to the
executable???




Reply With Quote
  #3  
Old   
unc27932@yahoo.com
 
Posts: n/a

Default Re: ForEach Loop, getting filename - help? - 02-12-2006 , 06:48 PM



Nice article - I've done everything you did in your article, up until
the last part, concerning the expression & tying the expression to a
variable. Do I need to do this? I thought in the execute process
task, it would just use the variable in the StandardInputVariable
property, which was my variable.....

To answer your question though - the variable does not contain the
value, resulting in the ExecuteProcess task being unable to do anything
with it. It's just an empty string, b/c when I look at the far right
tab, the processing results (or whatever it's called), the error is
basically...

"C:\path\program.exe" "" had trouble executing

or something remotely similar - sorry - not at my the same machine now.
In the empty double quotes above, there should be a filename, such as:

"C:\path\program.exe" "C:\path\testfile.txt"

Basically my package succesfully is...

1) enumerating the correct number of files
2) performing the execute process task (i.e. the program opens)

....but the filename is never there.


Allan Mitchell wrote:
Quote:
Hello Corey,

So are you saying that the variable does not contain the value or that the
ExecuteProcess task is unable to use it?

If the former then have a look at this article in which we discuss doing
what you are trying to do

http://www.sqlis.com/default.aspx?55


You could add a breakpoint on the ForEach enumerator to break on each iteration
of the loop. This way you can use a watch to find out wht value is being
stired in the variable.




Allan Mitchell
www.SQLDTS.com
www.SQLIS.com
www.Konesans.com

Using 2005, SSIS...

OK - I'm trying to loop through all the *.txt files in a certain
directory, and using each filename, call an executable, passing the
filename as an argument to the executable. I started by adding a
foreach loop container, and made sure it was foreach file enumerator
type. I chose the appropriate directory, and put in my *.txt filter,
and chose to use the fully qualified name. On the variable mappings
page, I created a new variabe (User::FileName), and saved it. Then I
added the execute process task inside the for each loop container,
calling the executable in the execute process task. I then chose the
User::FileName variable as the StandardInputVariable. And it won't
work. It can't find the filename at all. It does it 3 times (which is
the # of files) but it's not finding the filename.

What do I need to do in order to get the filename passed to the
executable???



Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: ForEach Loop, getting filename - help? - 02-13-2006 , 03:58 PM



Hello Corey,


Assign the result of the loop to a variable and then use that in you Execute
Process task.


Allan Mitchell
www.SQLDTS.com
www.SQLIS.com
www.Konesans.com

Quote:
Nice article - I've done everything you did in your article, up until
the last part, concerning the expression & tying the expression to a
variable. Do I need to do this? I thought in the execute process
task, it would just use the variable in the StandardInputVariable
property, which was my variable.....

To answer your question though - the variable does not contain the
value, resulting in the ExecuteProcess task being unable to do
anything with it. It's just an empty string, b/c when I look at the
far right tab, the processing results (or whatever it's called), the
error is basically...

"C:\path\program.exe" "" had trouble executing

or something remotely similar - sorry - not at my the same machine
now.
In the empty double quotes above, there should be a filename, such
as:
"C:\path\program.exe" "C:\path\testfile.txt"

Basically my package succesfully is...

1) enumerating the correct number of files
2) performing the execute process task (i.e. the program opens)
...but the filename is never there.

Allan Mitchell wrote:

Hello Corey,

So are you saying that the variable does not contain the value or
that the ExecuteProcess task is unable to use it?

If the former then have a look at this article in which we discuss
doing what you are trying to do

http://www.sqlis.com/default.aspx?55

You could add a breakpoint on the ForEach enumerator to break on each
iteration of the loop. This way you can use a watch to find out wht
value is being stired in the variable.

Allan Mitchell
www.SQLDTS.com
www.SQLIS.com
www.Konesans.com
Using 2005, SSIS...

OK - I'm trying to loop through all the *.txt files in a certain
directory, and using each filename, call an executable, passing the
filename as an argument to the executable. I started by adding a
foreach loop container, and made sure it was foreach file enumerator
type. I chose the appropriate directory, and put in my *.txt
filter, and chose to use the fully qualified name. On the variable
mappings page, I created a new variabe (User::FileName), and saved
it. Then I added the execute process task inside the for each loop
container, calling the executable in the execute process task. I
then chose the User::FileName variable as the StandardInputVariable.
And it won't work. It can't find the filename at all. It does it 3
times (which is the # of files) but it's not finding the filename.

What do I need to do in order to get the filename passed to the
executable???




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.