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

  • 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

  • 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[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply