Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSIS Task to Tell if Any Files Exist in Any Subfolder Within a Root Folder? Expand / Collapse
Author
Message
Posted Wednesday, April 2, 2014 11:46 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, July 5, 2014 8:31 AM
Points: 31, Visits: 220
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.
Post #1557818
Posted Thursday, April 3, 2014 12:05 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:26 AM
Points: 13,358, Visits: 10,223
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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1557823
Posted Thursday, April 3, 2014 7:21 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, July 5, 2014 8:31 AM
Points: 31, Visits: 220
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.
Post #1557964
Posted Thursday, April 3, 2014 9:45 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:26 AM
Points: 13,358, Visits: 10,223
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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1558062
Posted Friday, April 4, 2014 12:27 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:50 AM
Points: 4,986, Visits: 11,684
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1558379
Posted Friday, April 4, 2014 7:49 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, July 5, 2014 8:31 AM
Points: 31, Visits: 220
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.
Post #1558512
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse