Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server 2005 Integration Services
»
finding filepath, subdirectories, and...
finding filepath, subdirectories, and filenames
Rate Topic
Display Mode
Topic Options
Author
Message
light_wt
light_wt
Posted Friday, January 21, 2011 4:48 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Thursday, May 02, 2013 9:15 AM
Points: 165,
Visits: 258
in my local drive, i have a directory, d:\data\ with unlimited subdirectories liked the following:
d:\data\a\a.txt
d:\data\a\a2.txt
d:\data\a\a3.txt
d:\data\b\b.txt
d:\data\b\b2.txt
d:\data\b\b3.txt
d:\data\c\cc.txt
d:\data\c\c2.txt
d:\data\d\d.txt
d:\data\d\d2.txt
I created a package with multiple flat file connections and each connection has a Data Flow Task and a Script Compont will look into the assigned connection and find the files, liked:
For Each fileName In Directory.GetFiles(Me.Connections.ImportFilesDir.AcquireConnection(Nothing).ToString())
Output0Buffer.AddRow()
Output0Buffer.Filename = fileName
Next
These filenames then will be worked on with Derived column and store into a SQL table.
I have got a new requirement to use only one flat file connection to look for the txt files.
I was trying to use a table to store each of the path, such as d:\data\a, d:\data\b\, d:\data\c and use ForEach to enumerate them. I don't know how pass the values, such as d:\data\a, d:\data\b, and etc to a DFT which will write the result into the SQL table.
Am I taking the correct approach?
Is there an example of something liked this on the web I can follow, I am new to this type of SSIS.
Thanks.
Post #1051888
Phil Parkin
Phil Parkin
Posted Saturday, January 22, 2011 9:10 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Today @ 9:29 AM
Points: 4,240,
Visits: 9,487
Do the text files all have the same structure (column names, column types and number of columns)?
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1051963
lijnenjoost
lijnenjoost
Posted Monday, January 24, 2011 12:21 AM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 11:59 PM
Points: 22,
Visits: 184
1) Run a query to get your folders from that table with an Execture SQL Task (resultset=
Full result set
) and store the result in a variable.
2) Use a Foreach Loop to enumerate through that resultset in the variable (
Foreach ADO Enumerator
)
3) Store the folder in a variable (
Variable Mappings
in the Foreach Loop)
4) Use a new Foreach Loop within the first Foreach Loop. That should be a
Foreach File Enumerator
. Use an expression to fill the directory/folder part of that foreach loop with the variable of step 3.
Alternative:
If all file are within a parent folder with multiple subfolders, you could use the
Traverse subfolders
option.
Joost
http://microsoft-ssis.blogspot.com/
Post #1052200
Phil Parkin
Phil Parkin
Posted Monday, January 24, 2011 9:52 AM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Today @ 9:29 AM
Points: 4,240,
Visits: 9,487
I think the first sentence of the original post
in my local drive, i have a directory, d:\data\ with unlimited subdirectories liked the following:
points to your alternative as being the way to go.
But if the file structures are different, neither of your methods will work.
____________________________________________________________________________________________
Help us to help you. For better, quicker and more focused answers to your questions, consider following the advice in this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
If you are asking for help and your post does not contain a question, you should expect responses which do not contain any answers. Put a question mark in there somewhere - it's not rocket science.
Post #1052508
lijnenjoost
lijnenjoost
Posted Monday, January 24, 2011 1:19 PM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, May 07, 2013 11:59 PM
Points: 22,
Visits: 184
Phil Parkin (1/24/2011)
But if the file structures are different, neither of your methods will work.
If the files have different stuctures, the foreach loop won't work. Unless there is some way to distinguish them with for example the filename or filepath.
Joost
http://microsoft-ssis.blogspot.com/[url=http://microsoft-ssis.blogspot.com/][/url]
Post #1052657
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.