Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jblomqvist
Specialist
Specialist

3 questions about Loops for a beginner. Please help me answer :)

Hi,

I read this blog post: Loops in the Script

Here is an example of a Loop from the above blog:

   For each vFileName in Filelist ('C:\Path\*.txt')

      Load *,

         '$(vFileName)' as FileName

      From [$(vFileName)];

   Next vFileName

I do not understand the following about the above loop statement:

1) Is vFileName an in-built variable? I didn't have to declare it as a SET or LET statement prior so wondering how this works.

2) How does vFileName carry the path and the file name? It seems to work in combination with Filelist function above but I do not understand how.

3) Does the LOAD statement load one at a time? E.g. If I had a folder with 4 files, is this Loop running four times thus the LOAD statement load one file at a time?

1 Solution

Accepted Solutions
sunny_talwar

1) You are actually declaring a variable within the For Each statement.... Its not fixed, you can use anything

For Each VariableName in Filelist(.....)

2) For loop picks one file at a time and assigns its path to your VariableName

3) You are right, if there are 4 files, your load statement will run 4 times creating 4 tables. But since all the tables have same fields, they get auto-concatenated

View solution in original post

1 Reply
sunny_talwar

1) You are actually declaring a variable within the For Each statement.... Its not fixed, you can use anything

For Each VariableName in Filelist(.....)

2) For loop picks one file at a time and assigns its path to your VariableName

3) You are right, if there are 4 files, your load statement will run 4 times creating 4 tables. But since all the tables have same fields, they get auto-concatenated