SolvedPrivate

looping over files inside sub-sub folder

Posted on 2015-02-18
7
30 Views
Last Modified: 2016-06-19
i am very new to ssis and have a task to do. i have a folder named companies and inside that folder have two sub folders named: subfolder1 & subfolder2 and inside those subfolders i have sub-subfolders

companies
      -subfolder1
            --company1-A
                                       --file1.txt
                                       --file2.txt
            --company1-B
                                       --file1a.txt
      -subfolder2
            --company2-A
                                        --file1b.txt
            --company2-B

inside those company1-A, company1-B, company2-A & company2-B folders have text files which i want to loop over and print the name of the files along with the subfolder names(subfolder1 & subfolder2). hope my question is understandable. any feedback, comments & opinion would be deeply appreciated.
0
Comment
Question by:s_hausen
  • 2
  • 2
7 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 40618631
Hi,
solution for getting all files in a script task:
string[] allFiles = System.IO.Directory.GetFiles("C:\companies", "*.txt", System.IO.SearchOption.AllDirectories)

Open in new window


Other way would be to recursively run through the base directory, get files, get subdirectories, ...

Would the file name array (each being the complete path to the file) be enough? Or do you really need the distinct folder names as well?

What version of SSIS/SQL Server?
Thanks.
HTH
Rainer
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40618862
It's probably a stupid question, but why don't you use a specific file cataloger such as Filecats Standard, if all you need to do is print the file names?
0
 

Author Comment

by:s_hausen
ID: 40619151
i know its sound stupid but for right now, i just want to print the names of the sub folders and files inside sub-subfolder. the thing i'm looking is basically loop over that specific directory, print name of the files inside sub-subfolder,  and name of subdirectories. i'm using sql server 2012 and dts.
so if someone help me regarding this issue would be deeply appreciated.
0
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40619157
No, no - that's not stupid at all. I just want to know why you need to do it in SQL Server instead of using a separate cataloging program like the one I mentioned.
0
 

Accepted Solution

by:
s_hausen earned 0 total points
ID: 40625864
i got the solution from google:
http://microsoft-ssis.blogspot.com/2011/01/foreach-folder-enumerator.html

do appreciate everyone's input and help.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Here's a requirements document template for an integration project (also known as Extract-Transform-Load or ETL) based on my development experience as an SQL Server Information Services (SSIS) developer over the years.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now