There are so many examples for traverse files through folder using foreach loop container but i want to know how to traverse files using For loop container please help me
-
What is the motivation for wanting to use the for loop?Martin Smith– Martin Smith2016-04-20 14:28:09 +00:00Commented Apr 20, 2016 at 14:28
-
1Welcome to Stack Overflow. Please see How to Ask for information about how to get the best response from your questions. For example, you should add what you have tried to do specifically and what trouble you have had with what you tried to do. Otherwise, your question is too broad in scope for this site.Kateract– Kateract2016-04-20 14:35:01 +00:00Commented Apr 20, 2016 at 14:35
-
@Kateract +1 for a polite bit of advice to a new userBIDeveloper– BIDeveloper2016-04-20 15:11:16 +00:00Commented Apr 20, 2016 at 15:11
-
why do you want to use the for loop? In case you want to ignore some files this is more easily done by an expression task with a condition on a precedence constraint.Felix– Felix2016-04-24 10:11:39 +00:00Commented Apr 24, 2016 at 10:11
1 Answer
A For loop uses a range and a counter. If you wanted to use a For loop to traverse files in a folder, you would have to use a script task to count the number of files in the folder, and populate a variable with that number.
Then you would have to set a counter variable to 0, and set the For Loop to run while the counter is less than the file count, and increment the counter by 1 for each iteration.
Inside your loop you would need to get the file by its Index within the folder, presumably using the FileSystemObject in a Script Task.
Not particularly efficient, which is why the ForEach loop is usually used for files.
4 Comments
while(@MoreFilesToProcess) and that could be determined a number of ways. Eg. By the folder not being empty if you are archiving them elsewhere.