SSIS - Creating sub folders

  • What would be the best way to achieve the following, would it be a script task

    For each document type, create a top level folder

    for each document, a.Create a new sub folder beneath the Top Level folder if required. Subfolders names will start at ‘1’ with new folders incrementing this value by 1. A new subfolder will be created if:

    i.No subfolder currently exists.

    ii.The number of files in the currently used subfolder equals the Maximum subfolder size passed as a parameter to the SSIS package

  • Comes across as logic that might typically be encapsulated in a Script Task, yes.

  • Indeed it was, ended up withe the following

    Public Sub Main()

    Dim SourceDirectory As String = "E:\Data"

    Dim TargetDirectory As String = "E:\CN"

    Dim FileExtensionsToProcess As String = "*.pdf"

    Dim FileCounter As Integer = 1

    Dim FolderName As Integer = 1

    For Each FileName As String In System.IO.Directory.GetFiles(SourceDirectory, FileExtensionsToProcess)

    Dim FileOnly As String = System.IO.Path.GetFileName(FileName)

    Try

    If Not IO.Directory.Exists(IO.Path.Combine(TargetDirectory, FolderName.ToString())) Then

    IO.Directory.CreateDirectory(IO.Path.Combine(TargetDirectory, FolderName.ToString()))

    End If

    IO.File.Copy(FileName, IO.Path.Combine(TargetDirectory, IO.Path.Combine(FolderName.ToString(), FileOnly)))

    Catch

    End Try

    FileCounter += 1

    If (FileCounter Mod 1) = 0 Then

    FolderName += 1

    End If

    Next

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

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

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