• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 64
  • Last Modified:

looping over files inside sub-sub folder

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
s_hausen
Asked:
s_hausen
  • 2
  • 2
1 Solution
 
Rainer JeschorCommented:
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
 
Phillip BurtonCommented:
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
 
s_hausenAuthor Commented:
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
 
Phillip BurtonCommented:
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
 
s_hausenAuthor Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now