Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Recording File Name etc into a SQL Table using a loop for each directory required


Recording File Name etc into a SQL Table using a loop for each directory required

Author
Message
Debbie Edwards
Debbie Edwards
SSC-Addicted
SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)

Group: General Forum Members
Points: 466 Visits: 696
Hi,

Im starting a new project today. What I have is an area with 10 folders where services drop their files to be sent to schools.

What I'm wanting to do is log all these files in a table in SQL Server.

I have created a variable with each directory in which will hopefully feed into a For each loop container.
So the first directory is checked. Each file name is recorded. Id love to grab any information I can about the file. File Type. Size etc. Anything that I can log.

Once its recorded all the file names I want it to move onto the next folder in the variable.

Could anyone point me to any good documents on how to do this. Im normally dealing with for example XLS files and using a loop to add all the data into SQL. This is new to me!

Debbie
Evil Kraig F
Evil Kraig F
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5697 Visits: 7660
Debbie,

In this particular case, I think you'd be better off learning a bit of scripting. Don't worry, it won't be much. A Script Source component which does a DIR on the directories would be your best bet here though instead of trying to fight your way through looping with tools that don't really want to talk to the filesystem.

I don't have anything handy that uses the dir results as an array, but this little blurb will get you started.


Dim result As String
Dim SourceDirectory As String
Dim FilenamePattern As String
Dim Filename As String

Filename = ""
SourceDirectory = Dts.Variables("SourceDirectory").Value.ToString
FilenamePattern = Dts.Variables("FilenamePattern").Value.ToString

' Package is expected to be fired off at 1 minute intervals via job scheduling.
result = FileSystem.Dir(SourceDirectory & FilenamePattern)



If you get stuck let me know. I'll have to dig through some archives and find some older code I used that did close to what you're asking for.


- Craig Farrell

Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

For better assistance in answering your questions | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Debbie Edwards
Debbie Edwards
SSC-Addicted
SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)SSC-Addicted (466 reputation)

Group: General Forum Members
Points: 466 Visits: 696
Thanks for that!

Im still standed trying to get files from one lot of folders to another at the moment. This section is the icing on the cake. Once I get the first bit working I can get cracking on this.

It is quite dauting trying to get my head round th scripting tasks though. Thanks for the heads up on this one.

Debbie
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search