Link to home
Start Free TrialLog in
Avatar of s_hausen
s_hausen

asked on

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.
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

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
Avatar of Phillip Burton
Phillip Burton

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?
Avatar of s_hausen

ASKER

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of s_hausen
s_hausen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial