Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Recording File Name etc into a SQL Table using a loop for each directory required Expand / Collapse
Author
Message
Posted Monday, May 20, 2013 4:01 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, August 15, 2013 7:58 AM
Points: 423, Visits: 635
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
Post #1454466
Posted Tuesday, May 21, 2013 1:28 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:30 PM
Points: 6,138, Visits: 7,189
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
Post #1455188
Posted Wednesday, May 22, 2013 4:53 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, August 15, 2013 7:58 AM
Points: 423, Visits: 635
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
Post #1455420
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse