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 6162771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:42:38+00:00 2026-05-23T21:42:38+00:00

I’ve got an interesting challenge with SSIS. Using a for-each file enumerator, I need

  • 0

I’ve got an interesting challenge with SSIS. Using a for-each file enumerator, I need to pick the subfolder which has been most recently created, and then iterate through each of the files.

Perhaps an example would explain better. The folders look something like this:

c:\data\2011-0703

c:\data\2011-0626

c:\data\2011-0619

How could you get a for each file enumerator to pick the most recent folder? This could either be by looking at the creation date, or comparing the file names.

I’m guessing it would be done with an expression in the enumerator, just can’t work out how! Couldn’t find anything on the net either.

Thanks

  • 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-05-23T21:42:39+00:00Added an answer on May 23, 2026 at 9:42 pm

    Here is one possible option that you can achieve this with the help of Script Task. Following example shows how this can be done. The example was created in SSIS 2008 R2.

    Step-by-step process:

    1. Create three folders named 2011-0619, 2011-0626 and 2011-0703 in the folder path C:\temp\ as shown in screenshot #1. Make note of the Date created value of each of the folders.

    2. Place few files in each of the folders as shown in screenshots #2 – #4.

    3. On the SSIS package, create four variables as shown in screenshot #5. Set the variable RootFolder with value C:\temp\ (in your case this will be c:\data). Set the variable FilePattern with value *.*. Variable RecentFolder will be assigned with the recent folder path in the Script Task. To avoid design time errors, assign the variable RecentFolder with a valid file path. Variable FilePath will be assigned with values when the files are looped through in the recent folder.

    4. On the SSIS package, place a Script Task. Replace the Main() method within the Script Task with the script task code give under section Script task code (Get recent folder):. This script gets the list of folders in the root folder and loops through to check the creation datetime to pick the most recently created folder. The recently created folder path is then stored in the variable RecentFolder.

    5. On the SSIS package, place a Foreach Loop container and configure it as shown in screenshots #6 and #7.

    6. Place a Script Task inside the Foreach Loop container. Replace the Main() method within the Script Task with the script task code give under section Script task code (Display file names):. This script simply displays the names of files within the recently created folder.

    7. Once all tasks are configured, the package should look like as shown in screenshot #8.

    8. Screenshots #9 – #11 show that the package displays the file names in the recently created folder 2011-0703.

    Hope that helps.

    Script task code (Get recent folder):

    C# code that can be used only in SSIS 2008 and above.

    public void Main()
    {
        Variables varCollection = null;
    
        Dts.VariableDispenser.LockForRead("User::RootFolder");
        Dts.VariableDispenser.LockForWrite("User::RecentFolder");
        Dts.VariableDispenser.GetVariables(ref varCollection);
    
        string rootFolder = varCollection["User::RootFolder"].Value.ToString();
        DateTime previousFolderTime = DateTime.MinValue;
        string recentFolder = string.Empty;
    
        foreach (string subFolder in System.IO.Directory.GetDirectories(rootFolder))
        {
            DateTime currentFolderTime = System.IO.Directory.GetCreationTime(subFolder);
            if (previousFolderTime == DateTime.MinValue || previousFolderTime <= currentFolderTime)
            {
                previousFolderTime = currentFolderTime;
                recentFolder = subFolder;
            }
        }
    
        varCollection["User::RecentFolder"].Value = recentFolder;
    
        Dts.TaskResult = (int)ScriptResults.Success;
    }
    

    Script task code (Display file names):

    C# code that can be used only in SSIS 2008 and above.

    public void Main()
    {
        Variables varCollection = null;
    
        Dts.VariableDispenser.LockForRead("User::FilePath");
        Dts.VariableDispenser.GetVariables(ref varCollection);
    
        MessageBox.Show(varCollection["User::FilePath"].Value.ToString(), "File Path");
    
        Dts.TaskResult = (int)ScriptResults.Success;
    }
    

    Screenshot #1:

    1

    Screenshot #2:

    2

    Screenshot #3:

    3

    Screenshot #4:

    4

    Screenshot #5:

    5

    Screenshot #6:

    6

    Screenshot #7:

    7

    Screenshot #8:

    8

    Screenshot #9:

    9

    Screenshot #10:

    10

    Screenshot #11:

    11

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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.