Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
brad.mccollum
brad.mccollum
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 329
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.
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16443 Visits: 13202
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)



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
brad.mccollum
brad.mccollum
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 329
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.
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16443 Visits: 13202
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?



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8322 Visits: 19470
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?


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
brad.mccollum
brad.mccollum
Valued Member
Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)Valued Member (73 reputation)

Group: General Forum Members
Points: 73 Visits: 329
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search