SSIS Task to Tell if Any Files Exist in Any Subfolder Within a Root Folder?

  • Seems extremely simple but I'm not getting anywhere.

    I have a folder that clients can drop files into from day to day. The main/root folder is, for example, "c:\ClientFiles\".

    The subfolders can change from time to time but they're something like:

    - c:\ClientFiles\ABCCompany\

    - c:\ClientFiles\XYZCompany\

    - and so on...

    The client files that can be dropped in these randomly-named subfolders also don't follow any consistent naming pattern.

    What I'd like to do is to write some sort of SSIS Script Task that loops through the subfolders within the "c:\ClientFiles\" root folder and verifies that at least *ONE* file is found somewhere in one of those subfolders. It doesn't matter if just one file is found or 10,000 files are found... basically if at least 1 randomly-named files is found in any of the randomly-named subfolders within the root folder of "c:\ClientFiles\", then that's an indication that at least 1 client file has been uploaded into this directory since the last time the SSIS package ran and it's therefore o.k. to run this package once again.

    If there are no files at all found in at least 1 sub-folder, then the package doesn't need to continue running.

    Anyone have any sample code or suggestions as to how to perform this seemingly simple file / folder / subfolder search?

    Thanks.

  • There must be dozen of examples on the net on how to loop through directories.

    First Google result:

    How to: Iterate Through a Directory Tree (C# Programming Guide)

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • None at all of the examples I am finding actually work once I implement and modify the code for my particular situation. It only seems to loop through the root folder and does not look through files in the sub folders.

  • brad.mccollum (4/3/2014)


    None at all of the examples I am finding actually work once I implement and modify the code for my particular situation. It only seems to loop through the root folder and does not look through files in the sub folders.

    You need to implement some recursive coding.

    What do you have so far?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • brad.mccollum (4/3/2014)


    None at all of the examples I am finding actually work once I implement and modify the code for my particular situation. It only seems to loop through the root folder and does not look through files in the sub folders.

    It seems trivial. Presumably you looked into the syntax of Directory.GetFiles() (see link)?

    Using a searchOption of 'AllDirectories' would seem to be the answer, but I'm guessing that you've tried that already? What problems did you have?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I've finally figured this out after a bunch of trial and error.

    My code's on my laptop at home so I don't have access to it right now, but I'll post it here tonight to hopefully help someone else out in the future that runs into this same simple need.

    Thanks.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply