Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:41:26+00:00 2026-06-14T05:41:26+00:00

I’m trying to create an SSIS package to process files from a directory that

  • 0

I’m trying to create an SSIS package to process files from a directory that contains many years worth of files. The files are all named numerically, so to save processing everything, I want to pass SSIS a minimum number, and only enumerate files whose name (converted to a number) is higher than my minimum.

I’ve tried letting the ForEach File loop enumerate everything and then exclude files in a Script Task, but when dealing with hundreds of thousands of files, this is way too slow to be suitable.

The FileSpec property lets you specify a file mask to dictate which files you want in the collection, but I can’t quite see how to specify an expression to make that work, as it’s essentially a string match.

If there’s an expression within the component somewhere which basically says Should I Enumerate? - Yes / No, that would be perfect. I’ve been experimenting with the below expression, but can’t find a property to which to apply it.

(DT_I4)REPLACE( SUBSTRING(@[User::ActiveFilePath],FINDSTRING( @[User::ActiveFilePath], “\”, 7 ) + 1 ,100),”.txt”,””) > @[User::MinIndexId] ? “True” : “False”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:41:27+00:00Added an answer on June 14, 2026 at 5:41 am

    From investigating how the ForEach loop works in SSIS (with a view to creating my own to solve the issue) it seems that the way it works (as far as I could see anyway) is to enumerate the file collection first, before any mask is specified. It’s hard to tell exactly what’s going on without seeing the underlying code for the ForEach loop but it seems to be doing it this way, resulting in slow performance when dealing with over 100k files.

    While @Siva’s solution is fantastically detailed and definitely an improvement over my initial approach, it is essentially just the same process, except using an Expression Task to test the filename, rather than a Script Task (this does seem to offer some improvement).

    So, I decided to take a totally different approach and rather than use a file-based ForEach loop, enumerate the collection myself in a Script Task, apply my filtering logic, and then iterate over the remaining results. This is what I did:

    Sample Control Flow showing a Script Task to enumerate the files feeding into a ForEach Variable Enumerator

    In my Script Task, I use the asynchronous DirectoryInfo.EnumerateFiles method, which is the recommended approach for large file collections, as it allows streaming, rather than having to wait for the entire collection to be created before applying any logic.

    Here’s the code:

    public void Main()
    {
        string sourceDir = Dts.Variables["SourceDirectory"].Value.ToString();
        int minJobId = (int)Dts.Variables["MinIndexId"].Value;
    
        //Enumerate file collection (using Enumerate Files to allow us to start processing immediately
        List<string> activeFiles = new List<string>();
    
        System.Threading.Tasks.Task listTask = System.Threading.Tasks.Task.Factory.StartNew(() =>
        {
             DirectoryInfo dir = new DirectoryInfo(sourceDir);
             foreach (FileInfo f in dir.EnumerateFiles("*.txt"))
             {
                  FileInfo file = f;
                  string filePath = file.FullName;
                  string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                  int jobId = Convert.ToInt32(fileName.Substring(0, fileName.IndexOf(".txt")));
    
                  if (jobId > minJobId)
                       activeFiles.Add(filePath);
             }
        });
    
        //Wait here for completion
        System.Threading.Tasks.Task.WaitAll(new System.Threading.Tasks.Task[] { listTask });
        Dts.Variables["ActiveFilenames"].Value = activeFiles;
        Dts.TaskResult = (int)ScriptResults.Success;
    }
    

    So, I enumerate the collection, applying my logic as files are discovered and immediately adding the file path to my list for output. Once complete, I then assign this to an SSIS Object variable named ActiveFilenames which I’ll use as the collection for my ForEach loop.

    I configured the ForEach loop as a ForEach From Variable Enumerator, which now iterates over a much smaller collection (Post-filtered List<string> compared to what I can only assume was an unfiltered List<FileInfo> or something similar in SSIS’ built-in ForEach File Enumerator.

    So the tasks inside my loop can just be dedicated to processing the data, since it has already been filtered before hitting the loop. Although it doesn’t seem to be doing much different to either my initial package or Siva’s example, in production (for this particular case, anyway) it seems like filtering the collection and enumerating asynchronously provides a massive boost over using the built in ForEach File Enumerator.

    I’m going to continue investigating the ForEach loop container and see if I can replicate this logic in a custom component. If I get this working I’ll post a link in the comments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.