SolvedPrivate

looping over files inside sub-sub folder

Posted on 2015-02-18
7
53 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

705 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